diff --git a/Sources/php_script/script/config.php b/Sources/php_script/script/config.php index c604963..c4ed787 100644 --- a/Sources/php_script/script/config.php +++ b/Sources/php_script/script/config.php @@ -1,13 +1,22 @@ fetch_row()){ //For all the row in the database - if (strcmp($row[0], $id) == 0) { //If the user is found in the database - $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 -} diff --git a/Sources/php_script/script/index.php b/Sources/php_script/script/index.php deleted file mode 100644 index f6595e4..0000000 --- a/Sources/php_script/script/index.php +++ /dev/null @@ -1,5 +0,0 @@ - \ No newline at end of file diff --git a/Sources/php_script/script/insert.php b/Sources/php_script/script/insert.php deleted file mode 100644 index 84ffd22..0000000 --- a/Sources/php_script/script/insert.php +++ /dev/null @@ -1,26 +0,0 @@ -10;"; - $results = mysqli_query($connect, $query); - */ - $query = "DELETE FROM gps WHERE id='$id';"; //Delete the actual line and replace this line with the next lines - $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 -} \ No newline at end of file diff --git a/Sources/php_script/script/insertAndMakeListUser.php b/Sources/php_script/script/insertAndMakeListUser.php new file mode 100644 index 0000000..f81f726 --- /dev/null +++ b/Sources/php_script/script/insertAndMakeListUser.php @@ -0,0 +1,68 @@ +10;"; + $results = mysqli_query($connect, $query); + */ + + $query = "SELECT id FROM gps WHERE id='$id'"; + $results = mysqli_query($res, $query); //Execute the SQL command + + if (empty($results)){ + + $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 + + }else{ + + $query = "UPDATE gps SET latitude='$latitude', longitude='$longitude', idMusic='$idMusic' WHERE id='$id'"; //Delete the actual line and replace this line with the next lines + + } + + mysqli_query($res, $query); + + $query = "SELECT * FROM gps WHERE id != '$id'"; //Browse all the database + $results = mysqli_query($res, $query); //Execute the SQL command + $listUser = []; //Set the listUser to an empty list + + while ($row = $results->fetch_row()) { //For all the row in the database + + $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 = metersBetweenTwoUser($latitude, $longitude, $lat2, $lng2); //With the function meters, determinate 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 + + } + } + return (json_encode($listUser)); //Return an encode array in json, so flutter ca=n interpret it + + } else { //If the method POST return nothing + + return 3; //Return a code error + + } +} \ No newline at end of file