Пример #1
0
<?php

require_once 'functions.php';
require_once 'db_connect.php';
$fab = new fab();
switch ($_POST['funct']) {
    case 'search':
        if (isset($_POST['search']) && !empty($_POST['search'])) {
            echo search($_POST['search']);
        }
        break;
    case 'getFabs':
        if (isset($_POST['leftUpperBounds'], $_POST['rightLowerBounds']) && !empty($_POST['leftUpperBounds']) && !empty($_POST['rightLowerBounds'])) {
            echo $fab->getFabs($_POST['leftUpperBounds'], $_POST['rightLowerBounds'], $conn);
        }
        break;
    case 'createFab':
        if (isset($_POST['address'], $_POST['location'], $_POST['name'], $_POST['imageURL']) && !empty($_POST['address']) && !empty($_POST['location']) && !empty($_POST['name']) && !empty($_POST['imageURL'])) {
            $fab->createFab($_POST['address'], $_POST['location'], $_POST['name'], $_POST['imageURL'], $_SESSION['group']);
        }
        break;
    case 'getStatus':
        echo $fab->getStatus($_POST['id'], $conn);
        break;
    case 'createDemoInfo':
        echo $fab->createDemoInfo($_POST['id'], $conn);
        break;
}
function error($msg)
{
    // error handling
<?php

require_once 'functions.php';
require_once 'db_connect.php';
$fab = new fab();
if (isset($_POST['name'], $_POST['id'], $_POST['lat'], $_POST['lng'], $_POST['street'], $_POST['number'], $_POST['city'], $_POST['postalCode']) && !empty($_POST['name']) && !empty($_POST['lat']) && !empty($_POST['lng'])) {
    foreach ($_POST as $value) {
        if (empty($value)) {
            $value = null;
        }
    }
    $address = ['location' => ['lat' => floatval($_POST['lat']), 'lng' => floatval($_POST['lng'])], 'street' => htmlentities($_POST['street']), 'number' => htmlentities($_POST['number']), 'city' => htmlentities($_POST['city']), 'postalCode' => htmlentities($_POST['postalCode'])];
    $fab->createFab($address, htmlentities($_POST['name']), $_POST['id'], $conn);
} else {
    header('location: ../newFab.php');
}