Przejdź do treści

raporty-fm.php

<?php
/*
 * Template Name: Raporty FM
 * description: >-
  Szablon dla strony Raporty FM.
 */

function get_fm_notes($cupii){
    global $wpdb;
    $table_name = $wpdb->prefix . "tripetto_entries";
    $cupii_esc = esc_sql( $cupii );
    $sql = "SELECT 
                JSON_EXTRACT(entry, '$.created'),  
                JSON_EXTRACT(entry, '$.fields[1].string'),
                JSON_EXTRACT(entry, '$.fields[4].string')
            FROM 
                {$table_name} 
            WHERE 
                form_id = '111' 
            AND 
                JSON_EXTRACT(entry, '$.fields[1].string') = {$cupii}";
    $result = $wpdb->get_results( $sql );

    display_fm_notes($result);
}

function display_fm_notes($notes) {
    foreach ($notes as $note) {
        echo "<tr>";
        echo "<td>" . str_replace('"','', $note->{'JSON_EXTRACT(entry, \'$.fields[1].string\')'}) . "</td>";
        echo "<td>" . substr(str_replace('T', ' ',str_replace('"','', $note->{'JSON_EXTRACT(entry, \'$.created\')'})), 0, 19) . "</td>";
        echo "<td>" . str_replace('"','', $note->{'JSON_EXTRACT(entry, \'$.fields[4].string\')'}) . "</td>";
        echo "</tr>";
    }
}


?>

<html lang="pl">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Raporty FM</title>
  </head>
  <body>
    <div id="head-bar">
        <div id="formular" class="formular">
            <form method="get" id="formular-inputs" class="formular-inputs">
                <button id='close-button' class="formular-close-icon" onclick="showSearchBox()">_</button>
                <label for="cupii">Cupii:</label>
                <input type="number" name="cupii" placeholder="Podaj CUPII usługi."  required/>
                <!-- <label for="date-picker-from">Od: </label>
                <input type="datetime-local" id="date-picker-from" />
                <label for="date-picker-till">Do: </label>
                <input type="datetime-local" id="date-picker-till" /> -->
                <input type="submit" value="Szukaj" id="submit-btn" onclick="showTable()"/>
            </form>
            <button id='search-button' class="formular-search-icon active" onmouseenter="showSearchBox()">🔍</button>
        </div>
    </div>

    <div id="results" class="results active">      

        <table >
            <thead>
                <tr>
                    <th id="t_cupii">Cupii</th>
                    <th id="t_date">Data i godzina</th>
                    <th id="t_note">Treść alarmu</th>
                </tr>
            </thead>
            <tbody>
                <?php
                if (isset($_GET['cupii'])) {
                    $cupii = $_GET['cupii'];
                    get_fm_notes($cupii);
                }
                ?>
            </tbody>
        </table>
    </div>

    <script>
        let isSearchActive = false;

        function showSearchBox() {
            const formular = document.getElementById('formular');
            const inputs = document.getElementById('formular-inputs');
            const searchBtn = document.getElementById('search-button');
            const closeBtn = document.getElementById('search-button');

            if (isSearchActive) {
                formular.classList.remove('active');
                inputs.classList.remove('active');
                closeBtn.classList.remove('active');
                searchBtn.classList.add('active');
            } else {
                formular.classList.add('active');
                inputs.classList.add('active');
                closeBtn.classList.add('active');
                searchBtn.classList.remove('active');
            }

            isSearchActive = !isSearchActive;
        }
    </script>   


  </body>

<style>
    * {
        box-sizing: border-box;
        list-style: none;
        margin: 0;
        padding: 0;
        text-decoration: none;
    }

    body {
        display: flex;
        font-size: 1rem;
        font-weight: 600;
        align-items: flex-start;
        background-color:  #e7f0f2;
        color: black;
        font-family: "Abel", sans-serif;
        transition: all .5s ease;
    }

    input {
        margin: .5rem;
        border-radius: 10px;
        padding: .5rem;
        border-color: #1A535C;
    }

    label {
        margin: .5rem;
    }

    h1 {
        font-size: 2rem;
        padding: 1rem;
    }

    table {
        width: 100%;
        margin: .5rem;
        box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
    }

    table, th, td {
        border-collapse: collapse;
        padding: 15px;
        border-bottom: 1px dotted black;

    }

    th {
        text-align: start;
    }

    thead {
        background-color: #64dee9;
        z-index: 2;
    }

    tbody {
        position: relative;
        background-color: #F7FFF7; 
        font-size: .7rem;
        z-index: 1;
    }

    #head-bar {
        position: fixed;
        top: 0;
        z-index: 10;
    }

    #submit-btn {
        background-color: #56CBF9;
        font-weight: 400;
        font-weight: bold;
        transition: all 0.1s ease;
    }

    #submit-btn:hover{
        transform: scale(1.2);
        box-shadow: 0px 0px 4px 0px rgba(0, 0, 0, 0.75);
    }

    #submit-btn:active{
        filter: brightness(1.9);
    }

    .results.active {
        display: flex;
        width: 90vw;
        top: 80px;
        position: relative;
    }

    .results {
        display: none;
    }

    #close-button {
        width: 25px;
        height: 25px;
        padding: .5rem;
        border: 2px solid black;
        border-radius: 7px;
        font-weight: 600;
        background: #87CEFA;
        margin-left: 170px;
        justify-content: center; 
        align-items: center;
        display: flex;
    }

    #close-button:hover {
        transform: scale(1.2);
        box-shadow: 0px 0px 4px 0px rgba(0, 0, 0, 0.75);
    }

    #close-button:active{
        filter: brightness(1.9);
    }

    .formular.active {
        width: auto;
        height: auto;
    }

    .formular {
        display: flex;
        top: 10px;
        width: 50px;
        height: 50px;
        position: sticky;
        margin: 1rem;
        z-index: 3;
        background-color: #F7FFF7;
        padding: 2rem;
        border-radius: 10px;
        box-shadow: 0px 0px 4px 0px rgba(0, 0, 0, 0.75);
        transition: all .2s ease;
        flex-direction: row;
    }

    .formular-inputs {
        display: none;
    }

    .formular-search-icon.active {
        position: fixed;
        top: 20px;
        left: 25px;
        font-size: 2rem;
        background: none; 
        border: none;
        display: block;
    }

    .formular-search-icon {
        display: none;
    }

    .formular-inputs.active {
        display: flex;
        flex-direction: column;
    }

    #t_note {
        text-align: left;
    }


</style>
</html>