|
|
@@ -1,24 +1,26 @@ |
|
|
|
<?php |
|
|
|
|
|
|
|
session_start(); |
|
|
|
use Psr\Http\Message\ResponseInterface as Response; |
|
|
|
use Psr\Http\Message\ServerRequestInterface as Request; |
|
|
|
use Slim\Factory\AppFactory; |
|
|
|
Use Shop\DB\DB; |
|
|
|
|
|
|
|
require __DIR__ . '/../vendor/autoload.php'; |
|
|
|
|
|
|
|
class myDB extends \SQLite3 |
|
|
|
// maak namespace in een aangemaakte file en verplaats mydb |
|
|
|
/*class myDB extends \SQLite3 |
|
|
|
{ |
|
|
|
public function __construct() |
|
|
|
{ |
|
|
|
$this->open('../private/webshop.db'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
}*/ |
|
|
|
|
|
|
|
$app = AppFactory::create(); |
|
|
|
|
|
|
|
$app->map(['GET', 'POST'], "/orders/{client}/create", function (Request $request, Response $response, array $args) { |
|
|
|
if ($request->getMethod() == "GET") { |
|
|
|
$db2 = new myDB(); |
|
|
|
$db2 = new DB(); |
|
|
|
$stmt2 = $db2->prepare("SELECT * FROM clients WHERE id = " . $args['client']); |
|
|
|
$res2 = $stmt2->execute(); |
|
|
|
$a = $res2->fetchArray(SQLITE3_ASSOC); |
|
|
@@ -33,7 +35,7 @@ $app->map(['GET', 'POST'], "/orders/{client}/create", function (Request $request |
|
|
|
return $response; |
|
|
|
} else { |
|
|
|
$ref = $request->getParsedBody()['reference']; |
|
|
|
$db2 = new myDB(); |
|
|
|
$db2 = new DB(); |
|
|
|
$sql = "insert into orders (reference, customer_id, vat, subtotal, total) values ('" . $ref . "', " . $args['client'] . ",0,0,0)"; |
|
|
|
$db2->exec($sql); |
|
|
|
return $response->withHeader('Location', '/orders/' . $args['client']); |
|
|
@@ -42,7 +44,7 @@ $app->map(['GET', 'POST'], "/orders/{client}/create", function (Request $request |
|
|
|
|
|
|
|
// Route with optional params, see https://www.slimframework.com/docs/v4/objects/routing.html#how-to-create-routes section Optional segments |
|
|
|
$app->get('/orders[/{client}]', function (Request $request, Response $response, array $args) { |
|
|
|
$db = new myDB(); |
|
|
|
$db = new DB(); |
|
|
|
|
|
|
|
if ($args['client']) { |
|
|
|
// orders 1 client |
|
|
@@ -51,7 +53,7 @@ $app->get('/orders[/{client}]', function (Request $request, Response $response, |
|
|
|
$res = $stmt->execute(); |
|
|
|
|
|
|
|
// naam van de klant |
|
|
|
$db2 = new myDB(); |
|
|
|
$db2 = new DB(); |
|
|
|
$stmt2 = $db2->prepare("SELECT * FROM clients WHERE id = " . $args['client']); |
|
|
|
$res2 = $stmt2->execute(); |
|
|
|
$a = $res2->fetchArray(SQLITE3_ASSOC); |
|
|
@@ -86,7 +88,7 @@ $app->get('/orders[/{client}]', function (Request $request, Response $response, |
|
|
|
$app->map(['GET', 'POST'], "/order/{id}/create", function (Request $request, Response $response, array $args) { |
|
|
|
|
|
|
|
if ($request->getMethod() == "GET") { |
|
|
|
$db2 = new myDB(); |
|
|
|
$db2 = new DB(); |
|
|
|
$stmt2 = $db2->prepare("SELECT * FROM orders WHERE id = " . $args['id']); |
|
|
|
$res2 = $stmt2->execute(); |
|
|
|
$a = $res2->fetchArray(SQLITE3_ASSOC); |
|
|
@@ -105,7 +107,7 @@ $app->map(['GET', 'POST'], "/order/{id}/create", function (Request $request, Res |
|
|
|
} else { |
|
|
|
$productid = $request->getParsedBody()['id']; |
|
|
|
$qty = $request->getParsedBody()['qty']; |
|
|
|
$db2 = new myDB(); |
|
|
|
$db2 = new DB(); |
|
|
|
|
|
|
|
// vraag details van het product op |
|
|
|
$sqlproduct = "select * from products where id = " . $productid; |
|
|
@@ -135,7 +137,7 @@ $app->map(['GET', 'POST'], "/order/{id}/create", function (Request $request, Res |
|
|
|
|
|
|
|
$app->get('/order/{id}', function (Request $request, Response $response, array $args) { |
|
|
|
|
|
|
|
$db = new myDB(); |
|
|
|
$db = new DB(); |
|
|
|
|
|
|
|
// detail orderlijnen |
|
|
|
$sql = "SELECT * FROM order_lines o LEFT JOIN products p on o.product_id = p.id where o.order_id = " . $args['id']; |
|
|
@@ -143,7 +145,7 @@ $app->get('/order/{id}', function (Request $request, Response $response, array $ |
|
|
|
$res = $stmt->execute(); |
|
|
|
|
|
|
|
// detail order |
|
|
|
$db2 = new myDB(); |
|
|
|
$db2 = new DB(); |
|
|
|
$stmt = $db2->prepare("SELECT * FROM orders WHERE id = " . $args['id']); |
|
|
|
$res2 = $stmt->execute(); |
|
|
|
$a = $res2->fetchArray(SQLITE3_ASSOC); |
|
|
@@ -167,7 +169,7 @@ $app->get('/order/{id}', function (Request $request, Response $response, array $ |
|
|
|
|
|
|
|
|
|
|
|
$app->get('/customers', function (Request $request, Response $response, array $args) { |
|
|
|
$db = new myDB(); |
|
|
|
$db = new DB(); |
|
|
|
$sql = "SELECT * FROM clients"; |
|
|
|
$stmt = $db->prepare($sql); |
|
|
|
$res = $stmt->execute(); |