remotes/origin/mvc-implementation
commit
8ed568c2c4
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="PhpProjectSharedConfiguration" php_language_level="8.1">
|
||||||
|
<option name="suggestChangeDefaultLanguageLevel" value="false" />
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -1,14 +1,13 @@
|
|||||||
<?php
|
<?php
|
||||||
$username="dafldev";
|
$username="dafldev"; //Get the username
|
||||||
$host="89.83.53.34";
|
$host="89.83.53.34"; //Get the address IP of the hosting machine
|
||||||
$password="wrap";
|
$password="wrap"; //Get the password for the user selected
|
||||||
$db_name="positiondaflmusic";
|
$db_name="positiondaflmusic"; //Get the name of the database
|
||||||
|
|
||||||
$connect=mysqli_connect($host,$username,$password,$db_name);
|
$connect=mysqli_connect($host,$username,$password,$db_name); //Connecting to database
|
||||||
/*
|
|
||||||
if(!$connect)
|
if (mysqli_connect_errno()) { //Check if the connection failed
|
||||||
{
|
print(json_encode("Failed to connect to MySQL")); //Return a json string, so the dart script can interpret the error
|
||||||
print "Connection Failed";
|
exit(-1); //Send a return code as -1, so insert.php can know if the connection is successful
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
<?php
|
|
||||||
$dns = 'mysql:host=89.83.53.34;dbname=positiondaflmusic';
|
|
||||||
$user = 'dafldev';
|
|
||||||
$password = 'wrap';
|
|
||||||
try{
|
|
||||||
$db = new PDO ($dns, $user, $password);
|
|
||||||
}catch( PDOException $e){
|
|
||||||
$error = $e->getMessage();
|
|
||||||
echo $error;
|
|
||||||
}
|
|
@ -1,61 +1,57 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
function meters($lat1, $lng1, $lat2, $lng2): float
|
||||||
class distance
|
|
||||||
{
|
{
|
||||||
public function meters($lat1, $lng1, $lat2, $lng2): float
|
$earth_radius = 6378137; // Radius of the Earth in meters :
|
||||||
{
|
$rlo1 = deg2rad($lng1); //Transform the coordinate longitude1 from degree to radian
|
||||||
// Radius of the Earth in meters :
|
$rla1 = deg2rad($lat1); //Transform the coordinate latitude1 from degree to radian
|
||||||
$earth_radius = 6378137;
|
$rlo2 = deg2rad($lng2); //Transform the coordinate longitude2 from degree to radian
|
||||||
// Calculation of the distance between 2 GPS coordinates:
|
$rla2 = deg2rad($lat2); //Transform the coordinate latitude2 from degree to radian
|
||||||
$rlo1 = deg2rad($lng1);
|
$dlo = ($rlo2 - $rlo1) / 2; //Stock in $dlo the result of the calcul : ($rlo2 - $rlo1) / 2
|
||||||
$rla1 = deg2rad($lat1);
|
$dla = ($rla2 - $rla1) / 2; //Stock in $dla the result of the calcul : ($rla2 - $rla1) / 2
|
||||||
$rlo2 = deg2rad($lng2);
|
$a = (sin($dla) * sin($dla)) + cos($rla1) * cos($rla2) * (sin($dlo) * sin($dlo)); //Do some operations to return the distance in meters
|
||||||
$rla2 = deg2rad($lat2);
|
$d = 2 * atan2(sqrt($a), sqrt(1 - $a)); //Do some operations to return the distance in meters
|
||||||
$dlo = ($rlo2 - $rlo1) / 2;
|
return round($earth_radius * $d); // Return the distance in meters between 2 GPS points
|
||||||
$dla = ($rla2 - $rla1) / 2;
|
|
||||||
$a = (sin($dla) * sin($dla)) + cos($rla1) * cos($rla2) * (sin($dlo) * sin($dlo));
|
|
||||||
$d = 2 * atan2(sqrt($a), sqrt(1 - $a));
|
|
||||||
// Return the distance in meters between 2 GPS points
|
|
||||||
return round($earth_radius * $d);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$db=0;
|
|
||||||
$connect="";
|
|
||||||
require_once('db.php');
|
|
||||||
include "config.php";
|
|
||||||
$id = $_POST['id'];
|
|
||||||
$query = 'SELECT * FROM gps';
|
|
||||||
$stm = $db->prepare($query);
|
|
||||||
$stm->execute();
|
|
||||||
$row = $stm->fetchAll(PDO::FETCH_ASSOC);
|
|
||||||
$lat1=0;
|
|
||||||
$lng1=0;
|
|
||||||
$listUser=[];
|
|
||||||
Foreach ($row as $col) {
|
|
||||||
if (strcmp($col['id'], $id) == 0) {
|
|
||||||
$lat1 = $col['latitude'];
|
|
||||||
$lng1 = $col['longitude'];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if ($lat1==0 && $lng1==0){
|
$connect=""; //Else PHP send an error, "connect don't exist", but that work anyway, this is just to remove a fake error
|
||||||
print(json_encode("ERROR No user found in the database"));
|
$res=include "config.php"; //$res get the result of the calling of "config.php"
|
||||||
exit(1);
|
if ($res != 1){ //Check if config.php work
|
||||||
|
print (json_encode("Failed to connect to MySQL")); //Return a json string, so the dart script can interpret the error
|
||||||
}
|
}
|
||||||
|
if (!empty($_POST)) {
|
||||||
Foreach ($row as $col) {
|
$id = $_POST['id']; //Get the result of the POST method in id
|
||||||
if (strcmp($col['id'],$id)!=0) {
|
$query = 'SELECT * FROM gps'; //Browse all the database
|
||||||
$lat2 = $col['latitude'];
|
$results = mysqli_query($connect, $query); //Execute the SQL command
|
||||||
$lng2 = $col['longitude'];
|
$lat1 = 0; //Set $lat1 to test if the user exist
|
||||||
$userID = $col['id'];
|
$lng1 = 0; //Set $lng1 to test if the user exist
|
||||||
$idMusic = $col['idMusic'];
|
$listUser = []; //Set the listUser to an empty list
|
||||||
$dist = (new distance)->meters($lat1, $lng1, $lat2, $lng2);
|
while ($row = $results->fetch_row()){ //For all the row in the database
|
||||||
if ($dist <= 100) {
|
if (strcmp($row[0], $id) == 0) { //If the user is found in the database
|
||||||
$listUser[] = ['user' => $userID, 'music' => $idMusic]; }
|
$lat1 = $row[1]; //Set $lat1 to the latitude of the current user
|
||||||
|
$lng1 = $row[2]; //Set $lng1 to the longitude of the current user
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($lat1 == 0 && $lng1 == 0) { //Check if the user get found in the database
|
||||||
|
print(json_encode("ERROR No user found in the database")); //Return a json string, so the dart script can interpret the error
|
||||||
|
exit(1); //Exit the actual script
|
||||||
|
}
|
||||||
|
$results = mysqli_query($connect, $query); //Execute again the SQL command to restart the fetch_row()
|
||||||
|
while ($row = $results->fetch_row()) { //For all the row in the database
|
||||||
|
if (strcmp($row[0], $id) != 0) { //If the row is not the row of the current user
|
||||||
|
$lat2 = $row[1]; //Set $lat2 to the latitude of the user who is in the actual row
|
||||||
|
$lng2 = $row[2]; //Set $lng2 to the latitude of the user who is in the actual row
|
||||||
|
$userID = $row[0]; //Set $userID to the username of the user who is in the actual row
|
||||||
|
$idMusic = $row[3]; //Set $idMusic to the id of the actual song of the user who is in the actual row
|
||||||
|
$dist = meters($lat1, $lng1, $lat2, $lng2); //With the function meters, calcul of the distance between the current user and the user who is in the actual row
|
||||||
|
if ($dist <= 100) { //If the user in the actual row is less than 100 meters away of the current user
|
||||||
|
$listUser[] = ['user' => $userID, 'music' => $idMusic]; //Add the username and the ID of the song that user who is in the actual row is listening
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
print(json_encode($listUser)); //Return a json string of the list listUser
|
||||||
|
}else{ //If the method POST return nothing
|
||||||
|
print (json_encode("The POST didn't return any values")); //Return a json string, so the dart script can interpret the error
|
||||||
}
|
}
|
||||||
|
|
||||||
print(json_encode($listUser));
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,5 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
echo "Hello world Dafl for PHP"
|
|
||||||
|
|
||||||
?>
|
|
@ -1,20 +1,26 @@
|
|||||||
<?php
|
<?php
|
||||||
$connect="";
|
$connect=""; //Else PHP send an error, "connect don't exist", but that work anyway, this is just to remove a fake error
|
||||||
include "config.php";
|
$res=include "config.php"; //$res get the result of the calling of "config.php"
|
||||||
$id = mysqli_real_escape_string($connect, $_POST['id']);
|
if ($res != 1){ //Check if config.php work
|
||||||
$latitude = mysqli_real_escape_string($connect, $_POST['latitude']);
|
print (json_encode("Failed to connect to MySQL")); //Return a json string, so the dart script can interpret the error
|
||||||
$longitude = mysqli_real_escape_string($connect, $_POST['longitude']);
|
}
|
||||||
$idMusic = mysqli_real_escape_string($connect, $_POST['idMusic']);
|
if (!empty($_POST)) { //Check if the method POST return something
|
||||||
|
$id = mysqli_real_escape_string($connect, $_POST['id']); //Get the result of POST method
|
||||||
$latitude=doubleval($latitude);
|
$latitude = mysqli_real_escape_string($connect, $_POST['latitude']); //Get the result of POST method
|
||||||
$longitude=doubleval($longitude);
|
$longitude = mysqli_real_escape_string($connect, $_POST['longitude']); //Get the result of POST method
|
||||||
/*
|
$idMusic = mysqli_real_escape_string($connect, $_POST['idMusic']); //Get the result of POST method
|
||||||
$query = "DELETE FROM gps WHERE (SELECT TIMESTAMPDIFF(MINUTE,CURRENT_TIMESTAMP,dateLog))>10;";
|
$latitude = doubleval($latitude); //Convert a string to a double
|
||||||
$results = mysqli_query($connect, $query);
|
$longitude = doubleval($longitude); //Convert a string to a double
|
||||||
*/
|
/*
|
||||||
$query = "DELETE FROM gps WHERE id='$id';";
|
$query = "DELETE FROM gps WHERE (SELECT TIMESTAMPDIFF(MINUTE,CURRENT_TIMESTAMP,dateLog))>10;";
|
||||||
$results = mysqli_query($connect, $query);
|
$results = mysqli_query($connect, $query);
|
||||||
|
*/
|
||||||
$query = "INSERT INTO gps (id,latitude,longitude,idMusic,dateLog) VALUES('$id','$latitude','$longitude','$idMusic',CURRENT_TIMESTAMP);";
|
$query = "DELETE FROM gps WHERE id='$id';"; //Delete the actual line and replace this line with the next lines
|
||||||
$results = mysqli_query($connect, $query);
|
$results = mysqli_query($connect, $query); //Execute the SQL command
|
||||||
|
|
||||||
|
$query = "INSERT INTO gps (id,latitude,longitude,idMusic,dateLog)
|
||||||
|
VALUES('$id','$latitude','$longitude','$idMusic',CURRENT_TIMESTAMP);"; //Insert into the database the new data and new information about this user
|
||||||
|
$results = mysqli_query($connect, $query); //Execute the SQL command
|
||||||
|
}else{ //If the method POST return nothing
|
||||||
|
print (json_encode("The POST didn't return any values")); //Return a json string, so the dart script can interpret the error
|
||||||
|
}
|
Loading…
Reference in new issue