Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // First we execute our common code to connection to the database and start the session
- require("common.php");
- ?>
- <!DOCTYPE HTML>
- <!--
- Read Only by HTML5 UP
- html5up.net | @n33co
- Free for personal and commercial use under the CCA 3.0 license (html5up.net/license)
- -->
- <html>
- <head>
- <title>Pet Food Level Tracker</title>
- <meta charset="utf-8" />
- <meta name="viewport" content="width=device-width, initial-scale=1" />
- </head>
- <body>
- <!-- Header -->
- <section id="header">
- <header>
- <?php
- if(!empty($_SESSION['user']))
- {
- echo '<a href="logout.php"
- data-ajax="false">Logout</a>';
- echo "<br>Hello, ";
- echo htmlentities($_SESSION['user']['username'], ENT_QUOTES, 'UTF-8');
- echo "!<br><br>";
- }
- else
- {
- echo '<div data-role="main" class="ui-content">
- <a href="#myPopup" data-rel="popup" class="ui-btn ui-btn-inline ui-corner-all ui-icon-check ui-btn-icon-left">Login</a>
- <div data-role="popup" id="myPopup" class="ui-content" style="min-width:250px;">
- <h1>Login</h1>
- <form action="login.php" method="post" data-ajax="false">
- <div>
- <label for="usrnm" class="ui-hidden-accessible">Username:</label>
- <input type="text" name="username" id="usrnm" placeholder="Username">
- <label for="pswd" class="ui-hidden-accessible">Password:</label>
- <input type="password" name="password" id="pswd" placeholder="Password">
- <input type="submit" data-inline="true" value="Log in">
- </div>
- </form>
- </div>
- <br>
- <a href="register.php"
- data-ajax="false">Register</a><br><br>';
- }
- ?>
- <span class="image avatar"><img src="images/avatar.jpg" alt="" /></span>
- <h1 id="logo"><a href="#">Pet Food Level Tracker</a></h1>
- <!--<p>Tracking how much your pets devoured<br/>
- since 2016<br/>-->
- <?php
- if(!empty($_SESSION['user']))
- {
- echo "Tracking how much ";
- echo htmlentities($_SESSION['user']['username'], ENT_QUOTES, 'UTF-8');
- echo "'s pets devoured since 2016.<br/>";
- }
- else
- {
- echo "Tracking how much your pets devoured since 2016.";
- }
- ?>
- </header>
- <nav id="nav">
- <ul>
- <li><a href="#one">Food Tracker</a></li>
- <li><a href="#two">Settings</a></li>
- <li><a href="#three">About</a></li>
- <li><a href="http://www.fajnyblog.com">Blog</a></li> linka walnac tu
- </ul>
- </nav>
- <footer>
- <ul class="icons">
- <li><a href="#" class="icon fa-github"><span class="label">Github</span></a></li>
- <li><a href="#" class="icon fa-envelope"><span class="label">Email</span></a></li>
- </ul>
- </footer>
- </section>
- <!-- Wrapper -->
- <div id="wrapper">
- <!-- Main -->
- <div id="main">
- <!-- One -->
- <section id="one">
- <div class="container">
- <header class="major">
- <h2>Food Tracker</h2>
- <h4>Values:</h4>
- <?php
- if(!empty($_SESSION['user']))
- {
- $uid = $_SESSION['user']['id'];
- $query = "
- SELECT
- device_id
- FROM user_devices
- WHERE
- user_id = :uid
- ";
- $query_params = array(
- ':uid' => $uid,
- );
- try
- {
- $stmt = $db->prepare($query);
- $result = $stmt->execute($query_params);
- }
- catch(PDOException $ex)
- {
- die("Please don't leave anything blank!");
- }
- $row = $stmt->fetch();
- if($row)
- {
- $query = "
- SELECT
- timestamp,
- food_level,
- temp_level,
- humidity_level
- FROM device_values
- WHERE
- device_id = :devid
- ";
- $query_params = array(
- ':devid' => $row['device_id'],
- );
- try
- {
- $stmt = $db->prepare($query);
- $result = $stmt->execute($query_params);
- }
- catch(PDOException $ex)
- {
- die("Please don't leave anything blank!");
- }
- $timestampes = [];
- $food_levels = [];
- echo '<table border="1">
- <tbody>
- <tr>
- <td>timestamp</td>
- <td>food_level</td>
- <td>temp_level</td>
- <td>humidity_level</td>
- </tr>
- ';
- while($devices_row = $stmt->fetch())
- {
- echo '<tr><td>';
- echo $devices_row['timestamp'];
- array_push($timestampes, $devices_row['timestamp']);
- echo '</td><td>';
- echo $devices_row['food_level'];
- array_push($food_levels, $devices_row['food_level']);
- echo '</td><td>';
- echo $devices_row['temp_level'];
- echo '</td><td>';
- echo $devices_row['humidity_level'];
- echo '</td></tr>';
- }
- echo '</tr>
- </tbody>
- </table>';
- }
- }
- ?>
- </header>
- <p>
- <canvas id="myChart" width="300" height="300"></canvas>
- <canvas id="myChartTEMP" width="300" height="300"></canvas>
- </p>
- <section id="two">
- <div class="container">
- <header class="major">
- <h2>Settings</h2>
- </header>
- <p>
- <p>
- <?php
- if(!empty($_SESSION['user']))
- {
- echo 'Here you can set minimum amount of food, temperature and humidity levels, below which site will send a notification to your phone. You can also set a reminder for changing water in water bottle.';
- echo '<br><br>Your devices:<br><br>';
- $uid = $_SESSION['user']['id'];
- $query = "
- SELECT
- device_id
- FROM user_devices
- WHERE
- user_id = :uid
- ";
- $query_params = array(
- ':uid' => $uid,
- );
- try
- {
- $stmt = $db->prepare($query);
- $result = $stmt->execute($query_params);
- }
- catch(PDOException $ex)
- {
- die("Please don't leave anything blank!");
- }
- while($devices_row = $stmt->fetch())
- {
- $query = "
- SELECT
- device_name,
- last_update
- FROM devices
- WHERE
- device_id = :devid
- ";
- $query_params = array(
- ':devid' => $devices_row['device_id'],
- );
- try
- {
- $stmt2 = $db->prepare($query);
- $result = $stmt2->execute($query_params);
- }
- catch(PDOException $ex)
- {
- die("Please don't leave anything blank!");
- }
- $device_info = $stmt2->fetch();
- if($device_info)
- {
- $query = "
- SELECT
- food_min,
- next_water_check,
- temp_min,
- temp_max,
- humidity_min,
- humidity_max
- FROM user_settings
- WHERE
- device_id = :device_id
- ";
- $query_params = array(
- ':device_id' => $devices_row['device_id'],
- );
- try
- {
- $stmt3 = $db->prepare($query);
- $result = $stmt3->execute($query_params);
- }
- catch(PDOException $ex)
- {
- die("Please don't leave anything blank!");
- }
- $device_settings = $stmt3->fetch();
- echo 'ID: ';
- echo $devices_row['device_id'];
- echo '<br>Device name: ';
- echo $device_info['device_name'];
- echo '<br>Last update: ';
- echo $device_info['last_update'];
- echo '<form action="insert.php" method="post" data-ajax="false">';
- echo '<input type="hidden" name="device_id" id="device_id" value="' ;
- echo $devices_row['device_id'];
- echo '"';
- echo '<br>Minimum amount of food in grams: <input type="number" min="1" name="food_min" id="food_min" value="';
- echo $device_settings['food_min'];
- echo '"><br>Next water level check on: <input type="timestamp" name="next_water_check" min="1" id="next_water_check" value="';
- echo $device_settings['next_water_check'];
- /*if ($device_settings['next_water_check'] != null)
- {
- echo $device_settings['next_water_check'];
- }
- else
- {
- $date = new DateTime();
- echo $date->format(Y-m-d H:i:s') . "\n";
- }*/
- echo '"><br>Temperature in Celsius degrees between: <input type="number" name="temp_min" min="1" max="50" id="temp_min" value="';
- echo $device_settings['temp_min'];
- echo '"><br>and: <input type="number" name="temp_max" min="1" max="50" id="temp_max" value="';
- echo $device_settings['temp_max'];
- echo '"><br>Humidity in % between:<input type="number" name="humidity_min" min="1" max="100" id="humidity_min" value="';
- echo $device_settings['humidity_min'];
- echo '"><br>and:<input type="number" name="humidity_max" min="1" max="100" id="humidity_max" value="';
- echo $device_settings['humidity_max'];
- echo '"><br>';
- echo '<input type="submit" value="Submit">
- </form>';
- }}
- {
- echo '<form action="devices.php" method="post" data-ajax="false">';
- echo 'Add new device.';
- echo '<br>Device name: <input type="text" name="device_name" id="device_name" value="">';
- echo '<br>Device ID: <input type="number" name="device_id" id="device_id" value="">';
- echo '<input type = "hidden" name="food_min" id="food_min" value= "0">';
- echo '<input type = "hidden" name="next_water_check" id="next_water_check" value= "0">';
- echo '<input type = "hidden" name="temp_min" id="temp_min" value= "0">';
- echo '<input type = "hidden" name="temp_max" id="temp_max" value= "1">';
- echo '<input type = "hidden" name="humidity_min" id="humidity_min" value= "0">';
- echo '<input type = "hidden" name="humidity_max" id="humidity_max" value= "0">';
- echo '<input type="submit" value="Add device">
- </form>';}
- }
- else
- {
- echo "Content here is available only to members. Please register and login!";
- }
- ?>
- </p>
- </div>
- </section>
- </div>
- </section>
- <section id="three">
- <div class="container">
- <header class="major">
- <h2>About</h2>
- <p>opis</p>
- </header>
- <p>
- chyba niepotrzebne
- </p>
- </div>
- </section>
- </div>
- <!-- Footer -->
- <section id="footer">
- <div class="container">
- <ul class="copyright">
- <li>© Untitled. All rights reserved.</li><li>Design: <a href="http://html5up.net">HTML5 UP</a></li>
- </ul>
- </div>
- </section>
- </div>
- <!-- Scripts -->
- <script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
- <script src="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
- <script src="assets/js/jquery.scrolly.min.js"></script>
- <script src="assets/js/skel.min.js"></script>
- <script src="assets/js/util.js"></script>
- <!--[if lte IE 8]><script src="assets/js/ie/respond.min.js"></script><![endif]-->
- <script src="assets/js/main.js"></script>
- <script src="assets/js/Chart.js"></script>
- <!--[if lte IE 8]><script src="assets/js/ie/html5shiv.js"></script><![endif]-->
- <link rel="stylesheet" href="assets/css/main.css" />
- <link rel="stylesheet" href="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css">
- <!--[if lte IE 8]><link rel="stylesheet" href="assets/css/ie8.css" /><![endif]-->
- <script>
- var ctx = $("#myChart");
- var myChart = new Chart(ctx, {
- type: 'line',
- data: {
- labels: [<?php
- foreach ($timestampes as $value)
- {
- echo '"';
- echo $value;
- echo '", ';
- }?>
- ],
- datasets: [{
- label: 'Food level',
- data: [<?php
- foreach ($food_levels as $value)
- {
- echo $value;
- echo ', ';
- }?>
- ],
- backgroundColor: [
- 'rgba(255, 99, 132, 0.2)',
- 'rgba(54, 162, 235, 0.2)',
- 'rgba(255, 206, 86, 0.2)',
- 'rgba(75, 192, 192, 0.2)',
- ],
- borderColor: [
- 'rgba(255,99,132,1)',
- 'rgba(54, 162, 235, 1)',
- 'rgba(255, 206, 86, 1)',
- 'rgba(75, 192, 192, 1)',
- ],
- borderWidth: 1
- }]
- },
- options: {
- scales: {
- yAxes: [{
- ticks: {
- beginAtZero:true
- }
- }]
- }
- }
- });
- </script>
- <script>
- var ctx = $("#myChartTEMP");
- var myChartTEMP = new Chart(ctx, {
- type: 'line',
- data: {
- labels: [<?php
- foreach ($timestampes as $value)
- {
- echo '"';
- echo $value;
- echo '", ';
- }?>
- ],
- datasets: [{
- label: 'Temperature level',
- data: [<?php
- foreach ($temp_level as $value)
- {
- echo $value;
- echo ', ';
- }?>
- ],
- backgroundColor: [
- 'rgba(255, 99, 132, 0.2)',
- 'rgba(54, 162, 235, 0.2)',
- 'rgba(255, 206, 86, 0.2)',
- 'rgba(75, 192, 192, 0.2)',
- ],
- borderColor: [
- 'rgba(255,99,132,1)',
- 'rgba(54, 162, 235, 1)',
- 'rgba(255, 206, 86, 1)',
- 'rgba(75, 192, 192, 1)',
- ],
- borderWidth: 1
- }]
- },
- options: {
- scales: {
- yAxes: [{
- ticks: {
- beginAtZero:true
- }
- }]
- }
- }
- });
- </script>
- </body>
- </html>
Add Comment
Please, Sign In to add comment