// Grab the time of the last sensor read $time_now = `date +"%Y-%m-%d %H:%M:%S"`; $time_last_t = `tail -n 1 /var/www/mycodo/log/sensor-t-tmp.log`; if ($time_last_t != '') { $time_explode = explode(" ", $time_last_t); $time_last_t = $time_explode[0] . '-' . $time_explode[1] . '-' . $time_explode[2] . ' ' . $time_explode[3] . ':' . $time_explode[4] . ':' . $time_explode[5]; } $time_last_ht = `tail -n 1 /var/www/mycodo/log/sensor-ht-tmp.log`; if ($time_last_ht != '') { $time_explode = explode(" ", $time_last_ht); $time_last_ht = $time_explode[0] . '-' . $time_explode[1] . '-' . $time_explode[2] . ' ' . $time_explode[3] . ':' . $time_explode[4] . ':' . $time_explode[5]; } $time_last_co2 = `tail -n 1 /var/www/mycodo/log/sensor-co2-tmp.log`; if ($time_last_co2 != '') { $time_explode = explode(" ", $time_last_co2); $time_last_co2 = $time_explode[0] . '-' . $time_explode[1] . '-' . $time_explode[2] . ' ' . $time_explode[3] . ':' . $time_explode[4] . ':' . $time_explode[5]; } $time_last = max($time_last_t, $time_last_ht, $time_last_co2); // Request to generate a graph if (isset($_POST['Graph'])) { if (!isset($_POST['graph_type'])) { setcookie('graph_type', 'separate', time() + 86400 * 10, "/"); $_COOKIE['graph_type'] = 'separate'; } else { setcookie('graph_type', $_POST['graph_type'], time() + 86400 * 10, "/"); $_COOKIE['graph_type'] = $_POST['graph_type']; } setcookie('graph_span', $_POST['graph_time_span'], time() + 86400 * 10, "/"); $_COOKIE['graph_span'] = $_POST['graph_time_span']; set_new_graph_id(); }
function get_graph_cookie($name) { switch ($name) { case 'id': // Check if cookie exists with properly-formatted graph ID if (isset($_COOKIE['graph_id'])) { if (ctype_alnum($_COOKIE['graph_id']) && !isset($_GET['Refresh'])) { // Generate graph if auto-refresh is on return $_COOKIE['graph_id']; } } return set_new_graph_id(); case 'type': // Check if cookie exists for graph type if (isset($_COOKIE['graph_type'])) { if ($_COOKIE['graph_type'] == 'combined' || $_COOKIE['graph_type'] == 'separate') { return $_COOKIE['graph_type']; } } setcookie('graph_type', 'default', time() + 86400 * 10, "/"); $_COOKIE['graph_type'] = 'default'; return $_COOKIE['graph_type']; case 'span': // Check if cookie exists for graph time span if (isset($_COOKIE['graph_span'])) { if ($_COOKIE['graph_span'] == '1h' || $_COOKIE['graph_span'] == '3h' || $_COOKIE['graph_span'] == '6h' || $_COOKIE['graph_span'] == '12h' || $_COOKIE['graph_span'] == '1d' || $_COOKIE['graph_span'] == '3d' || $_COOKIE['graph_span'] == '1w' || $_COOKIE['graph_span'] == '2w' || $_COOKIE['graph_span'] == '1m' || $_COOKIE['graph_span'] == '3m' || $_COOKIE['graph_span'] == '6m') { return $_COOKIE['graph_span']; } } setcookie('graph_span', 'default', time() + 86400 * 10, "/"); $_COOKIE['graph_span'] = 'default'; return $_COOKIE['graph_span']; } }