<?php

header('Access-Control-Allow-Origin: *');
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
    if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD']))
	header("Access-Control-Allow-Methods: GET, POST, OPTIONS");
    if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']))
	header("Access-Control-Allow-Headers: {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}");
    exit;
}

include './conn.php';



//session_start();
//if(isset($_SESSION['uid'])){


mysql_query("SET NAMES 'utf8'");


//$return_arr = array();
//
//$qryX = "SELECT hour from night_price";
//
//$fetch = mysql_query("SELECT hour from night_price");
//if ($fetch === FALSE) {
//    die(mysql_error()); // TODO: better error handling
//}
//while ($row = mysql_fetch_array($fetch, MYSQL_ASSOC)) {
//    $row_array['hour'] = $row['hour'];
//    array_push($return_arr, $row_array);
//}
//echo json_encode($return_arr);



$sql = "SELECT hour from night_price";
$query = mysql_query($sql);


$rows = array();

while ($r = mysql_fetch_assoc($query)) {

    foreach ($r as $value) {



//                 $rows[] = utf8_encode($value);
	$rows[] = $value;
    }
}

$json = json_encode($rows);






$qry = "SELECT child_seat_price, booster_seat_price, carrycot_price, additional_address_price, night_price_wien, night_price_other,  creditcard_price, from_airport_plus, from_to_minus FROM options WHERE id = '1' ";

$res = mysql_query($qry);
if ($res === FALSE) {
    die(mysql_error()); // TODO: better error handling
}
$num_row = mysql_num_rows($res);
$row = mysql_fetch_assoc($res);
if ($num_row == 1) {

    $child_seat_price = $row['child_seat_price'] - 0;
    $booster_seat_price = $row['booster_seat_price'] - 0;
    $carrycot_price = $row['carrycot_price'] - 0;
    $additional_address_price = $row['additional_address_price'] - 0;
    $night_price_wien = $row['night_price_wien'] - 0;
    $night_price_other = $row['night_price_other'] - 0;
    $creditcard_price = $row['creditcard_price'] - 0;
    $from_airport_plus = $row['from_airport_plus'] - 0;
    $from_to_minus = $row['from_to_minus'] - 0;


    echo json_encode(array(
	'child_seat_price' => $child_seat_price,
	'booster_seat_price' => $booster_seat_price,
	'carrycot_price' => $carrycot_price,
	'additional_address_price' => $additional_address_price,
	'night_price_wien' => $night_price_wien,
	'night_price_other' => $night_price_other,
	'creditcard_price' => $creditcard_price,
	'from_airport_plus' => $from_airport_plus,
	'from_to_minus' => $from_to_minus,
	'nightprice' => $json
    ));
}



//}