public static function consumption($v) { $vid = Vehicle::getVehicle($v); $users = User::getUserIDs($vid["idvehicle"]); if ($users != NULL) { $uid = array(); //usersIDs foreach ($users as $key => $value) { array_push($uid, intval($users[$key]["iduser"])); } $consumption = array(); //consumption by userID foreach ($uid as $key => $value) { $data = Data::getDataBrowse($value); if ($data != NULL && $data["max"] != NULL && $data["min"] != NULL && $data["fuel"] != NULL) { $avg = intval($data["fuel"]) / (intval($data["max"]) - intval($data["min"])) * 100; array_push($consumption, $avg); } } if (!empty($consumption)) { $avg = round(array_sum($consumption) / count($consumption), 2) . "L/100km"; $min = round(min($consumption), 2) . "L/100km"; $max = round(max($consumption), 2) . "L/100km"; return [$avg, $min, $max]; } } }
<?php require_once 'Vehicle.php'; require_once 'db_init.php'; $isPost = filter_input(INPUT_SERVER, 'REQUEST_METHOD') == 'POST'; $invalid = TRUE; $message = "Invalid input!"; if ($isPost) { $rules = array('vehicle_name' => array('filters' => FILTER_SANITIZE_SPECIAL_CHARS, 'filter' => FILTER_VALIDATE_REGEXP, 'options' => array("regexp" => "/^[a-zA-Z\\s0-9]{2,45}\$/"))); $sent = filter_input_array(INPUT_POST, $rules); $exists = Vehicle::getVehicle($sent["vehicle_name"]); if ($exists == NULL && $sent["vehicle_name"] != FALSE && $sent["vehicle_name"] != NULL) { try { Vehicle::addVehicle($sent["vehicle_name"]); header("Location: ../html/admin.php"); } catch (PDOException $e) { die($e->getMessage()); } } else { $message = $message . " Vehicle already exists!"; } } if ($invalid) { ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Invalid</title> <link href='https://fonts.googleapis.com/css?family=Open+Sans+Condensed:300' rel='stylesheet' type='text/css'>
<?php require_once 'User.php'; require_once 'Vehicle.php'; require_once 'db_init.php'; $isPost = filter_input(INPUT_SERVER, 'REQUEST_METHOD') == 'POST'; $invalid = TRUE; $message = "Invalid input!"; if ($isPost) { $rules = array('full_nameSU' => array('filters' => FILTER_SANITIZE_SPECIAL_CHARS, 'filter' => FILTER_VALIDATE_REGEXP, 'options' => array("regexp" => "/^[a-zA-Z\\s,.-]{6,22}\$/")), 'e_mailSU' => array('filters' => FILTER_SANITIZE_SPECIAL_CHARS, 'filter' => FILTER_VALIDATE_REGEXP, 'options' => array("regexp" => "/^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\\.[a-zA-Z0-9-.]+\$/")), 'usernameSU' => array('filters' => FILTER_SANITIZE_SPECIAL_CHARS, 'filter' => FILTER_VALIDATE_REGEXP, 'options' => array("regexp" => "/^[a-zA-Z0-9_-]{5,16}\$/")), 'passwordSU' => array('filter' => FILTER_VALIDATE_REGEXP, 'options' => array("regexp" => "/^[a-zA-Z0-9_-]{6,18}\$/")), 'passwordSUC' => array('filter' => FILTER_VALIDATE_REGEXP, 'options' => array("regexp" => "/^[a-zA-Z0-9_-]{6,18}\$/"))); $sent = filter_input_array(INPUT_POST, $rules); $exists = User::getUser($sent["usernameSU"]); $v = filter_input(INPUT_POST, "vehicleSU", FILTER_SANITIZE_STRING); $vehicle = Vehicle::getVehicle($v); $vid = $vehicle["idvehicle"]; if ($exists == NULL && $sent["passwordSU"] == $sent["passwordSUC"]) { try { $hash = password_hash($sent["passwordSU"], PASSWORD_DEFAULT); User::addUser($sent["usernameSU"], $sent["e_mailSU"], $sent["full_nameSU"], $hash, $vid); header("Location: ../index.php"); } catch (PDOException $e) { die($e->getMessage()); } } else { $message = $message . " Username already exists!"; } } if ($invalid) { ?> <!DOCTYPE html>