Afegits fitxers de backend
This commit is contained in:
parent
d69be27c72
commit
127431a7de
15
backend/config.php
Normal file
15
backend/config.php
Normal file
|
@ -0,0 +1,15 @@
|
|||
<?php
|
||||
header('Access-Control-Allow-Origin: *');
|
||||
header('Access-Control-Allow-Methods: POST, GET, DELETE, PUT, PATCH, OPTIONS');
|
||||
header('Access-Control-Allow-Headers: token, Content-Type');
|
||||
header('Access-Control-Max-Age: 1728000');
|
||||
header('Content-Length:0');
|
||||
header('Content-Type: text/plain');
|
||||
|
||||
$host = "localhost";
|
||||
$user = "country_stats";
|
||||
$password = "country_stats";
|
||||
$db = "country_stats";
|
||||
|
||||
$con = mysqli_connect($host, $user, $password, $db) or die ("could not connect to DB");
|
||||
?>
|
15
backend/delete.php
Normal file
15
backend/delete.php
Normal file
|
@ -0,0 +1,15 @@
|
|||
<?php
|
||||
include "config.php";
|
||||
$input = file_get_contents('php://input');
|
||||
$response = array();
|
||||
$sqlString = "DELETE FROM cs_countries WHERE cs_country_id = $input";
|
||||
$sql = mysqli_query($con, $sqlString);
|
||||
if($sql){
|
||||
$response["message"] = "OK";
|
||||
}else{
|
||||
$response["message"] = "KO";
|
||||
}
|
||||
|
||||
echo json_encode($response);
|
||||
|
||||
?>
|
24
backend/insert.php
Normal file
24
backend/insert.php
Normal file
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
include "config.php";
|
||||
$input = file_get_contents('php://input');
|
||||
$data = json_decode($input, true);
|
||||
$response = array();
|
||||
|
||||
$countryName = $data["countryName"];
|
||||
$countryContinent = $data["countryContinent"];
|
||||
$countryArea = $data["countryArea"];
|
||||
$countryPopulation = $data["countryPopulation"];
|
||||
$countryDrivingSide = $data["countryDrivingSide"];
|
||||
|
||||
$sqlQuery = "INSERT INTO `cs_countries` (`cs_country_id`, `cs_country_name`, `cs_country_continent`,";
|
||||
$sqlQuery += " `cs_country_area`, `cs_country_population`, `cs_country_drivingSide`";
|
||||
$sqlQuery += " VALUES (NULL, '$countryName', ' $countryContinent', $countryArea, $countryPopulation, '$countryDrivingSide')";
|
||||
|
||||
$sql = mysqli_query($con, $sqlQuery);
|
||||
if($sql){
|
||||
$response["message"] = "OK";
|
||||
}else{
|
||||
$response["message"] = "KO";
|
||||
}
|
||||
echo json_encode($response);
|
||||
?>
|
24
backend/insert_new.php
Normal file
24
backend/insert_new.php
Normal file
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
include "config.php";
|
||||
$input = file_get_contents('php://input');
|
||||
$data = json_decode($input, true);
|
||||
$response = array();
|
||||
|
||||
$countryName = $data["countryName"];
|
||||
$countryContinent = $data["countryContinent"];
|
||||
$countryArea = $data["countryArea"];
|
||||
$countryPopulation = $data["countryPopulation"];
|
||||
$countryDrivingSide = $data["countryDrivingSide"];
|
||||
|
||||
$sqlQuery = "INSERT INTO `cs_countries` (`cs_country_id`, `cs_country_name`, `cs_country_continent`,";
|
||||
$sqlQuery += " `cs_country_area`, `cs_country_population`, `cs_country_drivingSide`";
|
||||
$sqlQuery += " VALUES (NULL, '$countryName', ' $countryContinent', $countryArea, $countryPopulation, '$countryDrivingSide')";
|
||||
|
||||
$sql = mysqli_query($con, $sqlQuery);
|
||||
if($sql){
|
||||
$response["message"] = "OK";
|
||||
}else{
|
||||
$response["message"] = "KO";
|
||||
}
|
||||
echo json_encode($response);
|
||||
?>
|
58
backend/insert_old.php
Normal file
58
backend/insert_old.php
Normal file
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
include "config.php";
|
||||
$response = array();
|
||||
|
||||
$name = $_POST["countryName"];
|
||||
$continent = $_POST["countryContinent"];
|
||||
$area = $_POST["countryArea"];
|
||||
$population = $_POST["countryPopulation"];
|
||||
$drivingSide = $_POST["countryDrivingSide"];
|
||||
|
||||
$flag = $_FILES["countryFlag"];
|
||||
|
||||
$target_dir = "assets/img/flags/";
|
||||
$imageType = strtolower(pathinfo($flag['name'],PATHINFO_EXTENSION));
|
||||
$file_name = fileNamer() . "." . $imageType;
|
||||
$target_file = $target_dir . $file_name;
|
||||
|
||||
$uploadOk = 1;
|
||||
|
||||
// Check if image file is a actual image or fake image
|
||||
if(true) {
|
||||
$check = getimagesize($flag["tmp_name"]);
|
||||
if($check !== false) {
|
||||
echo "File is an image - " . $check["mime"] . ".";
|
||||
} else {
|
||||
echo "File is not an image.";
|
||||
$uploadOk = 0;
|
||||
}
|
||||
if (move_uploaded_file($flag["tmp_name"], $target_file)) {
|
||||
echo "The file ". htmlspecialchars( basename( $flag["name"])). " has been uploaded.";
|
||||
$response["message"] = "OK";
|
||||
|
||||
} else {
|
||||
echo "Sorry, there was an error uploading your file.";
|
||||
$uploadOk = 0;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$sqlString = "INSERT INTO cs_countries (cs_country_name, cs_country_continent, cs_country_area, cs_country_population, cs_country_drivingSide, cs_country_flag)";
|
||||
$sqlString .= " VALUES ('$name', '$continent', $area, $population, '$drivingSide', '$file_name')";
|
||||
$sql = mysqli_query($con, $sqlString);
|
||||
if($sql){
|
||||
$response["message"] = "OK";
|
||||
}else{
|
||||
$response["message"] = "KO";
|
||||
}
|
||||
|
||||
|
||||
function fileNamer() {
|
||||
$today = date('Ymd');
|
||||
$range = $today - $startDate;
|
||||
$rand = rand(1000, 9999);
|
||||
return $today . "-" . $rand;
|
||||
}
|
||||
|
||||
echo json_encode($response);
|
||||
?>
|
14
backend/read.php
Normal file
14
backend/read.php
Normal file
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
include "config.php";
|
||||
|
||||
$sqlString = "SELECT * FROM cs_countries";
|
||||
$sth = mysqli_query($con, $sqlString);
|
||||
$output = array();
|
||||
|
||||
while ($row = mysqli_fetch_assoc($sth)) {
|
||||
$output[] = $row;
|
||||
}
|
||||
|
||||
echo json_encode($output);
|
||||
|
||||
?>
|
37
backend/read_new.php
Normal file
37
backend/read_new.php
Normal file
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
header('Access-Control-Allow-Origin: *');
|
||||
header('Access-Control-Allow-Methods: POST, GET, DELETE, PUT, PATCH, OPTIONS');
|
||||
header('Access-Control-Allow-Headers: token, Content-Type');
|
||||
header('Access-Control-Max-Age: 1728000');
|
||||
header('Content-Length:0');
|
||||
header('Content-Type: text/plain');
|
||||
|
||||
$offset = $_GET["offset"];
|
||||
$limit = $_GET["limit"];
|
||||
|
||||
$request_url = 'https://restcountries.com/v3.1/all';
|
||||
$curl = curl_init($request_url);
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
||||
$response = curl_exec($curl);
|
||||
curl_close($curl);
|
||||
|
||||
$data = json_decode($response);
|
||||
|
||||
$countries = array_slice($data, $offset, $limit);
|
||||
$output = array();
|
||||
foreach ($countries as $country) {
|
||||
$obj = new stdClass();
|
||||
$obj->flag = $country->flags->png;
|
||||
$obj->name = $country->name->common;
|
||||
$obj->capital = $country->capital[0];
|
||||
$obj->continent = $country->continents[0];
|
||||
$obj->area = $country->area;
|
||||
$obj->population = $country->population;
|
||||
$obj->drivingSide = $country->car->side;
|
||||
array_push($output, $obj);
|
||||
}
|
||||
|
||||
echo json_encode($output);
|
||||
// echo json_encode($limit);
|
||||
|
||||
?>
|
14
backend/read_old.php
Normal file
14
backend/read_old.php
Normal file
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
include "config.php";
|
||||
|
||||
$sqlString = "SELECT * FROM cs_countries";
|
||||
$sth = mysqli_query($con, $sqlString);
|
||||
$output = array();
|
||||
|
||||
while ($row = mysqli_fetch_assoc($sth)) {
|
||||
$output[] = $row;
|
||||
}
|
||||
|
||||
echo json_encode($output);
|
||||
|
||||
?>
|
10
backend/test.php
Normal file
10
backend/test.php
Normal file
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
function fileNamer(){
|
||||
$today = date('YmdHi');
|
||||
$startDate = date('YmdHi', strtotime('2012-03-14 09:06:00'));
|
||||
$range = $today - $startDate;
|
||||
$rand = rand(0, $range);
|
||||
return $startDate + $rand;
|
||||
}
|
||||
echo fileNamer();
|
||||
?>
|
|
@ -13,25 +13,25 @@
|
|||
<ion-slide>
|
||||
<div class="slideDiv">
|
||||
<div class="slideTitle"><p>Country Stats</p></div>
|
||||
<img src="/assets/img/slides/slide1.jpg" />
|
||||
<img src="http://localhost/backend/assets/img/slides/slide1.jpg" />
|
||||
</div>
|
||||
</ion-slide>
|
||||
<ion-slide>
|
||||
<div class="slideDiv">
|
||||
<div class="slideTitle"><p>Save Stats from any Country</p></div>
|
||||
<img src="/assets/img/slides/slide2.jpg" />
|
||||
<img src="http://localhost/backend/assets/img/slides/slide2.jpg" />
|
||||
</div>
|
||||
</ion-slide>
|
||||
<ion-slide>
|
||||
<div class="slideDiv">
|
||||
<div class="slideTitle"><p>They'll probably never be useful</p></div>
|
||||
<img src="/assets/img/slides/slide3.jpg" />
|
||||
<img src="http://localhost/backend/assets/img/slides/slide3.jpg" />
|
||||
</div>
|
||||
</ion-slide>
|
||||
<ion-slide>
|
||||
<div class="slideDiv">
|
||||
<div class="slideTitle"><p>But that's not why you learn them, right?</p></div>
|
||||
<img src="/assets/img/slides/slide4.jpg" />
|
||||
<img src="http://localhost/backend/assets/img/slides/slide4.jpg" />
|
||||
</div>
|
||||
</ion-slide>
|
||||
|
||||
|
|
Loading…
Reference in a new issue