hanze/iwa-panda1

views/search_data.php in tak
Repositories | Summary | Log | Files

search_data.php (4311B) download


  1<?php
  2    include "views/navbar.php";
  3    include "utils/autoloader.php";
  4
  5    $db = new Lollipop\SQLDatabase("86.92.67.21", "friedel", "hailiwa", "wap2");
  6
  7    $weather = $db->get(Weather_data::class);
  8
  9    //$date_begin = '2023-04-04';
 10    //$date_end = '2023-04-05';
 11	
 12    $date_begin = "";
 13    $date_end = "";
 14    $station = "";
 15
 16    $query = array();
 17    if($_SERVER['REQUEST_METHOD'] == 'GET'){
 18        if(isset($_GET['date_begin']) && !empty($_GET['date_begin'])){
 19            $date_begin = ($_GET['date_begin'] . "%");
 20			$query["date_time"][">="] = $date_begin;
 21		}
 22        if(isset($_GET['date_end'])&& !empty($_GET['date_end'])){
 23            $date_end = ($_GET['date_end'] . "%");
 24			$query["date_time"]["<="] = $date_end;
 25		}
 26        if(isset($_GET['station']) && !empty($_GET['station'])){
 27            $station = ($_GET['station'] . "%");
 28			$query["station_name"]["="] = $station;
 29		}
 30
 31		if($query == null){
 32			$query["station_name"]["LIKE"] = "%";
 33		}
 34        $weather_data = $db->getDateRange(Weather_data::class, $query, "DESC");
 35		//var_dump($weather_data);
 36    }
 37?>
 38<html>
 39    <head>
 40        <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
 41        <link rel="stylesheet" type="text/css" href="/css/weerdata.css">
 42    </head>
 43    <body>
 44        <form class="d-flex" action="search_data" method="get">
 45            <input class="form-control me-2" type="text" name="date_begin" placeholder="Date begin (YYYY-MM-DD)" pattern="\d{4}-\d{2}-\d{2}" value=<?php ?>>
 46            <input class="form-control me-2" type="text" name="date_end" placeholder="Date end (YYYY-MM-DD)" pattern="\d{4}-\d{2}-\d{2}" value=<?php ?>>
 47            <input class="form-control me-2" type="text" name="station" placeholder="Search" aria-label="Search" value=<?php ?>>
 48            <button class="btn btn-outline-success" type="submit">Search</button>
 49        </form>
 50
 51        <?php
 52            // verification logic and $_SESSION start
 53            if ($weather_data != null) {?>
 54                <table class="table table-striped">
 55                    <thead>
 56                    <tr>
 57                        <th> Station name </th>
 58                        <th> Date & Time </th>
 59                        <th> Validated </th>
 60                        <th> Temperature </th>
 61                        <th> Dewpoint </th>
 62                        <th> Sea pressure </th>
 63                        <th> Station pressure </th>
 64                        <th> Visibility </th>
 65                        <th> Wind speed </th>
 66                        <th> Precipitation </th>
 67                        <th> Snow depth </th>
 68                        <th> Events </th>
 69                        <th> Cloud count </th>
 70                        <th> Wind direction </th>
 71                    </tr>
 72                    </thead>
 73                    <tbody>
 74
 75                    </tbody>
 76                <?php
 77                    foreach($weather_data as $data) {
 78                    $link = "/search_data?station=" . $data->station_name;
 79                    echo "<tr>";
 80                        echo "<td><a href='" . $link . "'>" . $data->station_name . "</a></td>";
 81                        echo "<td>" . $data->date_time . "</td>";
 82                        echo "<td>" . $data->validated . "</td>";
 83                        echo "<td>" . $data->temperature . "</td>";
 84                        echo "<td>" . $data->dew_point . "</td>";
 85                        echo "<td>" . $data->pressure_sea . "</td>";
 86                        echo "<td>" . $data->pressure_station . "</td>";
 87                        echo "<td>" . $data->visibility . "</td>";
 88                        echo "<td>" . $data->wind_speed . "</td>";
 89                        echo "<td>" . $data->precipitation . "</td>";
 90                        echo "<td>" . $data->snow_depth . "</td>";
 91                        echo "<td>" . $data->events . "</td>";
 92                        echo "<td>" . $data->cloud_count . "</td>";
 93                        echo "<td>" . $data->wind_direction . "</td>";
 94                    echo "</tr>";
 95                    }
 96                ?>
 97                    </tbody>
 98                    </table>
 99        <?php
100            } else {
101                echo "No data found.";
102            }
103        ?>
104    </body>
105</html>