Exemplo n.º 1
0
$services = array_map("intval", preg_grep_keys("/service__\\d+/", $_POST));
if (!count($services) > 0) {
    $error_message[] = "You should select at least one service";
    goto theExit;
}
$qparams = [];
$sql = "select p.name, p.email, service_type, period, price_fix, price_per_day, service_desc " . "from offered_service s, profile p " . "where s.profile_id = :id " . "and s.profile_id = p.id " . "and available = TRUE " . "and s.service_type in (" . implode($services, ', ') . ")";
$qparams[":id"] = $id;
$q = $db->prepare($sql);
$q->execute($qparams);
$servicelist = [];
$overall_price = 0;
while ($row = $q->fetch(PDO::FETCH_ASSOC)) {
    $dest_name = $row['name'];
    $dest_email = $row['email'];
    $datespair = parse_and_validate_dates($_POST['arrival__' . $row['service_type']], $_POST['departure__' . $row['service_type']]);
    if (!$datespair) {
        $error_message[] = "Invalid departure or arrival dates provided";
        goto theExit;
    }
    $service_tot_price = ($datespair[1]->diff($datespair[0], true)->days + 1) * $row['price_per_day'];
    $overall_price += $service_tot_price;
    $servicelist[] = ['type' => $row['service_type'], 'name' => ServiceType::GetTypes()[$row['service_type']], 'price_per_day' => $row['price_per_day'], 'datespair' => $datespair, 'tot_price' => $service_tot_price];
}
if (!isset($_POST['first_name']) || !isset($_POST['email_from']) || !isset($_POST['comments'])) {
    $error_message[] = "Please complete all the mandatory fields.";
}
$first_name = $_POST['first_name'];
// required
//$last_name = $_POST['last_name']; // required
$email_from = $_POST['email_from'];
Exemplo n.º 2
0
<?php

require 'init.php.inc';
?>

<?php 
if (!array_key_exists('arrival', $_POST) || !array_key_exists('departure', $_POST)) {
    die("Invalid parameters");
}
$datespair = parse_and_validate_dates($_POST['arrival'], $_POST['departure']);
if ($datespair == FALSE) {
    die("Invalid parameters");
}
list($arrival_date, $departure_date) = $datespair;
$services = array_map("intval", preg_grep_keys("/service__\\d+/", $_POST));
$location_id = intval($_POST['locationid']);
$sql = "select p.id, p.name, p.description, p.picture, l.name as cityname, l.countryname, count(*) as services_no, array_to_json(array_agg(s.service_type)) as services_type,  array_to_json(array_agg(s.price_per_day)) as services_price_per_day " . "from profile p, offered_service s, porref_nearest l " . "where p.id = s.profile_id " . "and s.available = TRUE " . "and s.price_per_day is not null " . "and l.id = p.location_id " . "and (p.location_id = " . $location_id . " or " . $location_id . " = ANY (l.nearest)) " . "and s.period @> '[" . $arrival_date->format('Y-m-d') . ", " . $departure_date->format('Y-m-d') . "]'::daterange ";
if (count($services) > 0) {
    $sql .= "and s.service_type in (" . implode($services, ', ') . ") ";
}
$sql .= "group by p.id, p.name, p.description, p.picture, l.name, l.countryname " . "order by count(*) desc";
$q = $db->prepare($sql);
$q->execute();
$result = [];
while ($row = $q->fetch(PDO::FETCH_ASSOC)) {
    $new_element = array_merge($row, ['stars' => isset($_SESSION['stars'][$row['id']]) ? $_SESSION['stars'][$row['id']] : ($_SESSION['stars'][$row['id']] = round(rand(1, 5), 1)), 'wished' => isset($_SESSION['favourites'][$row['id']]) && $_SESSION['favourites'][$row['id']], 'arrival' => $arrival_date->format(__DATEFORMAT), 'departure' => $departure_date->format(__DATEFORMAT)]);
    $types = json_decode($new_element['services_type']);
    $prices = json_decode($new_element['services_price_per_day']);
    $inqparams = [];
    $insql = "select service_type, available, period, price_fix, price_per_day " . "from offered_service " . "where profile_id = :id " . "and price_per_day is not null " . "and period @> '[" . $arrival_date->format('Y-m-d') . ", " . $departure_date->format('Y-m-d') . "]'::daterange ";
    $inqparams[":id"] = $row['id'];