<?php

//error_reporting(E_ALL);
//ini_set('display_errors', 1);
include './conn.php';


if (!empty($_POST["abholadresse"]) && $_POST["abholadresse"] != '') {

    $pickupdate = $_POST['pickupdate'];
    $hour = $_POST['hour'];
    $minute = $_POST['minute'];

    $abholadresse = $_POST['abholadresse'];
    $zieladresse = $_POST['zieladresse'];
    $addaddress = $_POST['addaddress'];
    $zusatzadresse1 = $_POST['zusatzadresse1'];
    $zusatzadresse2 = $_POST['zusatzadresse2'];
    $zusatzadresse3 = $_POST['zusatzadresse3'];
    $passengers = $_POST['passengers'];
    $suitcases = $_POST['suitcases'];
    $handlugage = $_POST['handlugage'];
    $boosterseat = $_POST['boosterseat'];
    $childseat = $_POST['childseat'];
    $carrycot = $_POST['carrycot'];
    $payment = $_POST['payment'];
    $salutation = $_POST['salutation'];
    $name = $_POST['name'];
    $surname = $_POST['surname'];
    $phone = $_POST['phone'];
    $email = $_POST['email'];
    $note = $_POST['note'];
    $rueckfahrt = $_POST['rueckfahrt'];
    $pickupdatereturn = $_POST['pickupdatereturn'];
    $hourreturn = $_POST['hourreturn'];
    $minutereturn = $_POST['minutereturn'];
    $price = $_POST['price'];
    $pricereturn = $_POST['pricereturn'];


    if ($addaddress == 'none') {
	$addaddress = '0';
    }
    if ($suitcases == 'none') {
	$suitcases = '0';
    }
    if ($handlugage == 'none') {
	$handlugage = '0';
    }
    if ($boosterseat == 'none') {
	$boosterseat = '0';
    }
    if ($childseat == 'none') {
	$childseat = '0';
    }
    if ($carrycot == 'none') {
	$carrycot = '0';
    }
    $carrycot = '0';

    $result = mysql_query("SELECT smtp_server,smtp_user,smtp_pass,smtp_email,sitename,session_time,sms_user,sms_password,sms_sys_zum,sms_sys_vom,sms_sys_zum_f,sms_sys_vom_f,sms_web_zum,sms_web_vom,child_seat_price,booster_seat_price,carrycot_price,additional_address_price,map_in_forms,invoice_year,sys_path,sys_port,night_price_wien,night_price_other,price_balance,creditcard_price,icons_in_form,email_trip_info,company_phone,company_url,company_atu,company_bankname,company_iban,company_konto,company_bic,company_blz,rechnung_h1,rechnung_header,company_admin,sms_send_name,sms_number_bottom,invoice_days,from_airport_plus,from_to_minus,backup_fahrten_email,order_number_prefix_web FROM options WHERE id = '1'");
    if ($result === FALSE) {
	die(mysql_error()); // TODO: better error handling
    }
    $row = mysql_fetch_array($result);

    $opt_smtp_server = $row['smtp_server'];
    $opt_smtp_user = $row['smtp_user'];
    $opt_smtp_pass = $row['smtp_pass'];
    $opt_smtp_email = $row['smtp_email'];
    $opt_sitename = $row['sitename'];
    $opt_session_time = $row['session_time'];
    $opt_sms_user = $row['sms_user'];
    $opt_sms_password = $row['sms_password'];
    $opt_sms_sys_zum = $row['sms_sys_zum'];
    $opt_sms_sys_vom = $row['sms_sys_vom'];
    $opt_sms_sys_zum_f = $row['sms_sys_zum_f'];
    $opt_sms_sys_vom_f = $row['sms_sys_vom_f'];
    $opt_sms_web_zum = $row['sms_web_zum'];
    $opt_sms_web_vom = $row['sms_web_vom'];
    $opt_child_seat_price = $row['child_seat_price'];
    $opt_booster_seat_price = $row['booster_seat_price'];
    $opt_carrycot_price = $row['carrycot_price'];
    $opt_additional_address_price = $row['additional_address_price'];
    $opt_map_in_forms = $row['map_in_forms'];
    $opt_invoice_year = $row['invoice_year'];
    $opt_sys_path = $row['sys_path'];
    $opt_sys_port = $row['sys_port'];
    $opt_night_price_wien = $row['night_price_wien'];
    $opt_night_price_other = $row['night_price_other'];
    $opt_price_balance = $row['price_balance'];
    $opt_creditcard_price = $row['creditcard_price'];
    $opt_icons_in_form = $row['icons_in_form'];
    $opt_email_trip_info = $row['email_trip_info'];
    $opt_company_phone = $row['company_phone'];
    $opt_company_url = $row['company_url'];
    $opt_company_atu = $row['company_atu'];
    $opt_company_bankname = $row['company_bankname'];
    $opt_company_iban = $row['company_iban'];
    $opt_company_konto = $row['company_konto'];
    $opt_company_bic = $row['company_bic'];
    $opt_company_blz = $row['company_blz'];
    $opt_rechnung_h1 = $row['rechnung_h1'];
    $opt_rechnung_header = $row['rechnung_header'];
    $opt_company_admin = $row['company_admin'];
    $opt_sms_send_name = $row['sms_send_name'];
    $opt_sms_number_bottom = $row['sms_number_bottom'];
    $opt_invoice_days = $row['invoice_days'];
    $opt_from_airport_plus = $row['from_airport_plus'];
    $opt_from_to_minus = $row['from_to_minus'];
    $backup_fahrten_email = $row['backup_fahrten_email'];
    $order_number_prefix_web = $row['order_number_prefix_web'];



//    if ($passengers == '') {
//        $car = 'limo';
//    }
//    if ($suitcases == 'keine') {
//        $car = 'limo';
//    }
//    if ($suitcases <= '2') {
//        $car = 'limo';
//    }
//    if ($passengers <= '3') {
//        $car = 'limo';
//    }
//    if ($passengers <= 3 && $suitcases >= 3) {
//        $car = 'kombi';
//    }
//
//
//    if ($passengers == 4) {
//        $car = 'kombi';
//    }
//    if ($suitcases == 4) {
//        $car = 'van';
//    }
//    if ($suitcases <= 8 && $suitcases >= 5) {
//        $car = 'van';
//    }
//    if ($passengers <= 8 && $passengers >= 5) {
//        $car = 'van';
//    }





    $price = number_format((float) $price, 2, '.', '');
    $pricereturn = number_format((float) $pricereturn, 2, '.', '');


    $pickupdateSQL = date("Y-m-d", strtotime($pickupdate));
    $pickuptimeSQL = $hour . ':' . $minute . ':00';
    $pickup = 'AB';
    if ($passengers <= 3 || $suitcases <= 2) {
	$car_type = 'L';
    }
    if ($passengers == 4 || $suitcases >= 3) {
	$car_type = 'K';
    }
    if ($passengers >= 5 && $passengers <= 8 || $suitcases >= 5 && $suitcases <= 8) {
	$car_type = 'V';
    }




    setlocale(LC_TIME, 'de_DE', 'deu_deu');
    $datum = $pickupdate;
    $time = strtotime($datum);
    $month = date("Y-m", $time);

    function random_string($length) {
	$key = '';
	$keys = array_merge(range(0, 9));
	for ($i = 0; $i < $length; $i++) {
	    $key .= $keys[array_rand($keys)];
	}
	return $key;
    }

    function random_code($length) {
	$key = '';
	$keys = array_merge(range(0, 9), range('a', 'z'));
	for ($i = 0; $i < $length; $i++) {
	    $key .= $keys[array_rand($keys)];
	}
	return $key;
    }

    $rand = random_string(8);
    $order_no = $order_number_prefix_web . $rand;

    $confirm_code = md5($order_no);
    $order_date = date('Y-m-d H:i:s');
    if (!empty($_SERVER["HTTP_CLIENT_IP"])) {
	$customer_ip = $_SERVER["HTTP_CLIENT_IP"];
    } elseif (!empty($_SERVER["HTTP_X_FORWARDED_FOR"])) {
	$customer_ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
    } else {
	$customer_ip = $_SERVER["REMOTE_ADDR"];
    }



    $sqlchk = mysql_query("SELECT customer_no FROM customers WHERE email = '{$email}'");

    if (mysql_fetch_row($sqlchk)) {
	$result = mysql_query("SELECT customer_no FROM customers WHERE email = '{$email}'");
	$row = mysql_fetch_array($result);
	$customer_no = $row['customer_no'];
    } else {
	$customer_no = random_string(6);
	$pin = random_string(4);
	mysql_query("SET NAMES 'utf8'");
	mysql_query("INSERT INTO `customers` (customer_no, pin, salutation, name, surname, email, phone)
      VALUES ('$customer_no', '$pin', '$salutation', '$name', '$surname', '$email', '$phone')")or die(mysql_error());
    }


    if ($addaddress >= '1') {
	$zusatz1 = $zusatzadresse1;
    } else {
	$zusatz1 = '';
    }
    if ($addaddress >= '2') {
	$zusatz2 = $zusatzadresse2;
    } else {
	$zusatz2 = '';
    }
    if ($addaddress >= '3') {
	$zusatz3 = $zusatzadresse3;
    } else {
	$zusatz3 = '';
    }
    if ($addaddress >= '0') {
	$zusatz1 = '';
	$zusatz2 = '';
	$zusatz3 = '';
    }

    mysql_query("SET NAMES 'utf8'");

    $result = mysql_query("INSERT INTO `orders` (order_no, confirm_code, order_date, customer_ip, customer_no, pick_up_date, pick_up_time, pickup, salutation, name, surname,  phone, email, car_type, passengers, booster_seat, child_seat,  carrycot, suitcase, hand_luggage, additional_address, payment, note, price, cancellation, month, confirmed, paid,start_adresse, ziel_adresse, zusatzziel1, zusatzziel2, zusatzziel3)
      VALUES ('$order_no', '$confirm_code', '$order_date', '$customer_ip', '$customer_no', '$pickupdateSQL', '$pickuptimeSQL', '$pickup', '$salutation', '$name', '$surname', '$phone', '$email', '$car_type', '$passengers', '$boosterseat', '$childseat', '$carrycot', '$suitcases', '$handlugage', '$addaddress', '$payment', '$note', '$price', '0','$month', '0', '0', '$abholadresse', '$zieladresse', '$zusatz1', '$zusatz2', '$zusatz3') ")or die(mysql_error());


    if ($result) {
	$insertzum = "OK";
    } else {
	$insertzum = "ERROR";
    }










    if ($rueckfahrt == '1') {



	$order_noR = $order_no . '-R';
	$confirm_codeR = $confirm_code . '-R';
	$pick_up_date = date("Y-m-d", strtotime($pickupdatereturn));
	$pick_up_time = $hourreturn . ':' . $minutereturn . ':00';
	$pickup = 'AB';
	//$return_price = $price + 3;
	$priceQ = $pricereturn;
	//$price = str_replace(',', '.', $return_price);






	mysql_query("SET NAMES 'utf8'");

	$result = mysql_query("INSERT INTO `orders` (order_no, confirm_code, order_date, customer_ip, customer_no, pick_up_date, pick_up_time, pickup, salutation, name, surname,  phone, email, car_type, passengers, booster_seat, child_seat,  carrycot, suitcase, hand_luggage, additional_address, payment, note, price, cancellation, month, confirmed, paid,start_adresse, ziel_adresse, zusatzziel1, zusatzziel2, zusatzziel3)
      VALUES ('$order_noR', '$confirm_codeR', '$order_date', '$customer_ip', '$customer_no', '$pickupdateSQL', '$pickuptimeSQL', '$pickup', '$salutation', '$name', '$surname', '$phone', '$email', '$car_type', '$passengers', '$boosterseat', '$childseat', '$carrycot', '$suitcases', '$handlugage', '$addaddress', '$payment', '$note', '$pricereturn', '0','$month', '0', '0', '$zieladresse', '$abholadresse', '$zusatz1', '$zusatz2', '$zusatz3') ")or die(mysql_error());


	if ($result) {
	    $insertvom = "OK";
	} else {
	    $insertvom = "ERROR";
	}
    }



    if ($rueckfahrt == '1') {
	if ($insertzum == 'OK' && $insertvom == 'OK') {
	    $success = "OK";
	}
    } elseif ($rueckfahrt == '0') {
	if ($insertzum == 'OK') {
	    $success = "OK";
	}
    } else {
	$success = 'ERROR';
    }





    $priceM = str_replace('.', ',', $price);
    $pricereturnM = str_replace('.', ',', $pricereturn);




    if ($addaddress == '1') {
	$aa1 = '<tr><td style="font-size:20;font-weight:bolder;">Zusatzadresse</td><td></td></tr>
<tr><td style="padding:5px;">Zusatz Ziel 1</td><td style="padding:5px;">' . $zusatz1 . ' </td></tr>';
	$aa2 = '';
	$aa3 = '';
    } else if ($addaddress == '2') {
	$aa1 = '<tr><td style="font-size:20;font-weight:bolder;">Zusatzadresse</th><td></td></tr>
<tr><td style="padding:5px;">Zusatz Ziel 1</td><td style="padding:5px;">' . $zusatz1 . ' </td></tr>';
	$aa2 = '<tr><td style="padding:5px;">Zusatz Ziel 2</td><td style="padding:5px;">' . $zusatz2 . ' </td></tr>';
	$aa3 = '';
    } else if ($addaddress == '3') {
	$aa1 = '<tr><td style="font-size:20;font-weight:bolder;">Zusatzadresse</td><td></td></tr>
<tr><td style="padding:5px;">Zusatz Ziel 1</td><td style="padding:5px;">' . $zusatz1 . ' </td></tr>';
	$aa2 = '<tr><td style="padding:5px;">Zusatz Ziel 2</td><td style="padding:5px;">' . $zusatz2 . ' </td></tr>';
	$aa3 = '<tr><td style="padding:5px;">Zusatz Ziel 3</td><td style="padding:5px;">' . $zusatz3 . ' </td></tr>';
    } else if ($addaddress == '0' || $addaddress == '') {
	$aa1 = '';
	$aa2 = '';
	$aa3 = '';
    }


    $to = $email; // note the comma

    $subject = 'Auftragsbestätigung zu Ihrer Bestellung / Auftrags-Nr. ' . $order_no . ' / ' . $opt_sitename . ' ';

    $message = ' <!DOCTYPE html>
<html>
    <head>
        <title>Fahrt</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
    </head>
    <body>
<div>Sehr geehrter ' . $salutation . ' ' . $name . ' ' . $surname . '
<div>
<div>vielen Dank für Ihre Bestellung, die wir Ihnen wie folgt bestätigen:</div>
<div style="padding: 0 10px 0 10px; margin-top: 20px; margin-bottom: 35px;"></div>
<div>Ihre Kundennummer: ' . $customer_no . '</div><br>
<h3>Richtung - von A nach B</h3>

<table style="border-collapse: collapse;" border="1" width="500px;">
<tbody>
<tr>
<th>Bestelldetails</th>
<th>Bestellnummer: ' . $order_no . '</th>
</tr>
<tr>
<td style="padding: 5px;padding-left:30px;">Abholdatum und Uhrzeit</td>
<td style="padding: 5px;">' . $pickupdate . ' - ' . $hour . ':' . $minute . ' </td>
</tr>
<tr>
<td style="padding: 5px;padding-left:30px;">Abfahrt von</td>
<td style="padding: 5px;">' . $abholadresse . '</td>
</tr>
<tr>
<td style="padding: 5px;padding-left:30px;">Reiseziel nach</td>
<td style="padding: 5px;">' . $zieladresse . '</td>
</tr>
<tr>
<td style="padding: 5px;padding-left:30px;">Personen</td>
<td style="padding: 5px;">' . $passengers . '</td>
</tr>
<tr>
<td style="padding: 5px;padding-left:30px;">Koffer</td>
<td style="padding: 5px;">' . $suitcases . '</td>
</tr>
<tr>
<td style="padding: 5px;padding-left:30px;">Handgepäck</td>
<td style="padding: 5px;">' . $handlugage . '</td>
</tr>
<tr>
<td style="font-size:18;font-weight:bolder;">Kontaktinformationen</td>
<td> </td>
</tr>
<tr>
<td style="padding: 5px;padding-left:30px;">Name</td>
<td style="padding: 5px;">' . $name . ' ' . $surname . '</td>
</tr>
<tr>
<td style="padding: 5px;padding-left:30px;">E-Mail</td>
<td style="padding: 5px;">' . $email . '</td>
</tr>
<tr>
<td style="padding: 5px;padding-left:30px;">Telefonnummer</td>
<td style="padding: 5px;">' . $phone . '</td>
</tr>
<tr>
<td style="font-size:18;font-weight:bolder;">Zahlungsinfo</td>
<td> </td>
</tr>
<tr>
<td style="padding: 5px;padding-left:30px;">Zahlungsweise</td>
<td style="padding: 5px;">' . $payment . '</td>
</tr>
<tr>
<td style="font-size:18;font-weight:bolder;">Optionen</td>
<td> </td>
</tr>
<tr>
<td style="padding: 5px;padding-left:30px;">Kindersitz</td>
<td style="padding: 5px;">' . $childseat . '</td>
</tr>
<tr>
<td style="padding: 5px;padding-left:30px;">Kindersitzerhöhung</td>
<td style="padding: 5px;">' . $boosterseat . '</td>
</tr>
' . $aa1 . ' ' . $aa2 . ' ' . $aa3 . '
</tbody>
</table>
<h2>Preis: ' . $priceM . ' EUR</h2>

<div style="margin-top: 20px; margin-bottom: 40px;">Mit freundlichen Gr&uuml;&szlig;en <br /> Ihr ' . $opt_sitename . ' Team</div>

<p><strong>AIRPORT TRANSFER<br /> LIMOUSINENSERVICE ZUM FIXPREIS<br /> WEB: <a title="http://' . $opt_company_url . '/" href="http://' . $opt_company_url . '/">' . $opt_company_url . '</a><br /> E-Mail: <a title="mailto:' . $opt_smtp_email . '" href="mailto:' . $opt_smtp_email . '">' . $opt_smtp_email . '</a><br /> </strong></p>
<div style="font-size: 70%;"><strong>Vertraulichkeitserkl&auml;rung</strong><br /> Diese E-Mail enth&auml;lt Informationen, die rechtlich gesch&uuml;tzt oder vertraulich sein k&ouml;nnen. Sie ist ausschlie&szlig;lich f&uuml;r den angegebenen Empf&auml;nger bestimmt. Sollten Sie nicht der richtige Adressat sein oder diese E-Mail irrt&uuml;mlich erhalten haben, informieren Sie bitte unverz&uuml;glich den Absender und vernichten Sie diese E-Mail. Das unerlaubte Kopieren oder Offenlegen sowie die unbefugte Weitergabe dieser E-Mail ist nicht gestattet.</div>
<hr />

</div>
</div>
</div>
</body>
</html>
';


    require './imapMail/PHPMailerAutoload.php';
    $mail = new PHPMailer();

    $mail->IsSMTP();  // telling the class to use SMTP

    $mail->SMTPDebug = 0;
    // 0 = no output, 1 = errors and messages, 2 = messages only.

    $mail->SMTPAuth = true;  // enable SMTP authentication
    $mail->addReplyTo($opt_smtp_email, $opt_sitename);
    $mail->SMTPSecure = "tls";       // sets the prefix to the servier
    $mail->Host = $opt_smtp_server; // sets Gmail as the SMTP server
    $mail->Port = 587;       // set the SMTP port for the GMAIL

    $mail->Username = $opt_smtp_user;  // Gmail username
    $mail->Password = $opt_smtp_pass;      // Gmail password

    $mail->CharSet = 'UTF-8';
    $mail->SetFrom($opt_smtp_email, $opt_sitename);
    $mail->Subject = $subject;
    $mail->ContentType = 'text/html';
    $mail->IsHTML(true);

    $mail->Body = $message;
    // you may also use $mail->Body = file_get_contents('your_mail_template.html');
    if ($success == 'OK') {
	$mail->AddAddress($to, $name . ' ' . $surname);

	// you may also use this format $mail->AddAddress ($recipient);

	if (!$mail->Send()) {
	    $emailzum = 'ERROR';
	} else {
	    $emailzum = 'OK';
	}


	$mail = new PHPMailer();

	$mail->IsSMTP();  // telling the class to use SMTP

	$mail->SMTPDebug = 0;
	// 0 = no output, 1 = errors and messages, 2 = messages only.

	$mail->SMTPAuth = true;  // enable SMTP authentication
	$mail->addReplyTo($opt_smtp_email, $opt_sitename);
	$mail->SMTPSecure = "tls";       // sets the prefix to the servier
	$mail->Host = $opt_smtp_server; // sets Gmail as the SMTP server
	$mail->Port = 587;       // set the SMTP port for the GMAIL

	$mail->Username = $opt_smtp_user;  // Gmail username
	$mail->Password = $opt_smtp_pass;      // Gmail password

	$mail->CharSet = 'UTF-8';
	$mail->SetFrom($opt_smtp_email, $opt_sitename);
	$mail->Subject = 'NOVA VOZNJA - ' . $pickupdate . ' - ' . $hour . ':' . $minute;
	$mail->ContentType = 'text/html';
	$mail->IsHTML(true);

	$mail->Body = $message;
// you may also use $mail->Body = file_get_contents('your_mail_template.html');

	$mail->AddAddress($backup_fahrten_email, $backup_fahrten_email);
// you may also use this format $mail->AddAddress ($recipient);

	if (!$mail->Send()) {

	} else {

	}
    }
    //echo $success;



    if ($rueckfahrt == '1') {
	$to = $email; // note the comma

	$subject = 'Auftragsbestätigung zu Ihrer Bestellung / Auftrags-Nr. ' . $order_noR . ' / ' . $opt_sitename . ' ';

	$message = ' <!DOCTYPE html>
<html>
    <head>
        <title>Fahrt</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
    </head>
    <body>
<div>Sehr geehrter ' . $salutation . ' ' . $name . ' ' . $surname . '
<div>
<div>vielen Dank für Ihre Bestellung, die wir Ihnen wie folgt bestätigen:</div>
<div style="padding: 0 10px 0 10px; margin-top: 20px; margin-bottom: 35px;"></div>
<div>Ihre Kundennummer: ' . $customer_no . '</div><br>


<h3>Richtung - von A nach B</h3>

<table style="border-collapse: collapse;" border="1" width="500px;">
<tbody>
<tr>
<th>Bestelldetails</th>
<th>Bestellnummer: ' . $order_noR . '</th>
</tr>
<tr>
<td style="padding: 5px;padding-left:30px;">Abholdatum und Uhrzeit</td>
<td style="padding: 5px;">' . $pickupdatereturn . ' - ' . $hourreturn . ':' . $minutereturn . ' </td>
</tr>
<tr>
<td style="padding: 5px;padding-left:30px;">Abfahrt von</td>
<td style="padding: 5px;">' . $zieladresse . '</td>
</tr>
<tr>
<td style="padding: 5px;padding-left:30px;">Reiseziel nach</td>
<td style="padding: 5px;">' . $abholadresse . '</td>
</tr>
<tr>
<td style="padding: 5px;padding-left:30px;">Personen</td>
<td style="padding: 5px;">' . $passengers . '</td>
</tr>
<tr>
<td style="padding: 5px;padding-left:30px;">Koffer</td>
<td style="padding: 5px;">' . $suitcases . '</td>
</tr>
<tr>
<td style="padding: 5px;padding-left:30px;">Handgepäck</td>
<td style="padding: 5px;">' . $handlugage . '</td>
</tr>
<tr>
<td style="font-size:18;font-weight:bolder;">Kontaktinformationen</td>
<td> </td>
</tr>
<tr>
<td style="padding: 5px;padding-left:30px;">Name</td>
<td style="padding: 5px;">' . $name . ' ' . $surname . '</td>
</tr>
<tr>
<td style="padding: 5px;padding-left:30px;">E-Mail</td>
<td style="padding: 5px;">' . $email . '</td>
</tr>
<tr>
<td style="padding: 5px;padding-left:30px;">Telefonnummer</td>
<td style="padding: 5px;">' . $phone . '</td>
</tr>
<tr>
<td style="font-size:18;font-weight:bolder;">Zahlungsinfo</td>
<td> </td>
</tr>
<tr>
<td style="padding: 5px;padding-left:30px;">Zahlungsweise</td>
<td style="padding: 5px;">' . $payment . '</td>
</tr>
<tr>
<td style="font-size:18;font-weight:bolder;">Optionen</td>
<td> </td>
</tr>
<tr>
<td style="padding: 5px;padding-left:30px;">Kindersitz</td>
<td style="padding: 5px;">' . $childseat . '</td>
</tr>
<tr>
<td style="padding: 5px;padding-left:30px;">Kindersitzerhöhung</td>
<td style="padding: 5px;">' . $boosterseat . '</td>
</tr>
' . $aa1 . ' ' . $aa2 . ' ' . $aa3 . '
</tbody>
</table>
<h2>Preis: ' . $pricereturnM . ' EUR</h2>

<div style="margin-top: 20px; margin-bottom: 40px;">Mit freundlichen Gr&uuml;&szlig;en <br /> Ihr ' . $opt_sitename . ' Team</div>
<h4 style="padding: 0px; margin: 10px 0 0 0;">Wichtige Info!</h4>
<div>Lieber Kunde, Bitte machen sie keine Bestellung beim Fahrer da es vielleicht zu falschen Angaben f&uuml;hren kann und wir nicht f&uuml;r unsere Zuverl&auml;ssigkeit garantieren k&ouml;nnen.</div>
<p><strong>AIRPORT TRANSFER<br /> LIMOUSINENSERVICE ZUM FIXPREIS<br /><div style="displaynone">Tel.: ' . $opt_company_phone . '<br /></div>  WEB: <a title="http://' . $opt_company_url . '/" href="http://' . $opt_company_url . '/">' . $opt_company_url . '</a><br /> E-Mail: <a title="mailto:' . $opt_smtp_email . '" href="mailto:' . $opt_smtp_email . '">' . $opt_smtp_email . '</a><br /> </strong></p>
<div style="font-size: 70%;"><strong>Vertraulichkeitserkl&auml;rung</strong><br /> Diese E-Mail enth&auml;lt Informationen, die rechtlich gesch&uuml;tzt oder vertraulich sein k&ouml;nnen. Sie ist ausschlie&szlig;lich f&uuml;r den angegebenen Empf&auml;nger bestimmt. Sollten Sie nicht der richtige Adressat sein oder diese E-Mail irrt&uuml;mlich erhalten haben, informieren Sie bitte unverz&uuml;glich den Absender und vernichten Sie diese E-Mail. Das unerlaubte Kopieren oder Offenlegen sowie die unbefugte Weitergabe dieser E-Mail ist nicht gestattet.</div>
<hr />
</div>
</div>
</div>
</body>
</html>
';


	$mail = new PHPMailer();

	$mail->IsSMTP();  // telling the class to use SMTP

	$mail->SMTPDebug = 0;
	// 0 = no output, 1 = errors and messages, 2 = messages only.

	$mail->SMTPAuth = true;  // enable SMTP authentication
	$mail->addReplyTo($opt_smtp_email, $opt_sitename);
	$mail->SMTPSecure = "tls";       // sets the prefix to the servier
	$mail->Host = $opt_smtp_server; // sets Gmail as the SMTP server
	$mail->Port = 587;       // set the SMTP port for the GMAIL

	$mail->Username = $opt_smtp_user;  // Gmail username
	$mail->Password = $opt_smtp_pass;      // Gmail password

	$mail->CharSet = 'UTF-8';
	$mail->SetFrom($opt_smtp_email, $opt_sitename);
	$mail->Subject = $subject;
	$mail->ContentType = 'text/html';
	$mail->IsHTML(true);

	$mail->Body = $message;
	// you may also use $mail->Body = file_get_contents('your_mail_template.html');
	if ($success == 'OK') {
	    $mail->AddAddress($to, $name . ' ' . $surname);

	    // you may also use this format $mail->AddAddress ($recipient);

	    if (!$mail->Send()) {
		$emailvom = 'ERROR';
	    } else {
		$emailvom = 'OK';
	    }


	    $mail = new PHPMailer();

	    $mail->IsSMTP();  // telling the class to use SMTP

	    $mail->SMTPDebug = 0;
	    // 0 = no output, 1 = errors and messages, 2 = messages only.

	    $mail->SMTPAuth = true;  // enable SMTP authentication
	    $mail->addReplyTo($opt_smtp_email, $opt_sitename);
	    $mail->SMTPSecure = "tls";       // sets the prefix to the servier
	    $mail->Host = $opt_smtp_server; // sets Gmail as the SMTP server
	    $mail->Port = 587;       // set the SMTP port for the GMAIL

	    $mail->Username = $opt_smtp_user;  // Gmail username
	    $mail->Password = $opt_smtp_pass;      // Gmail password

	    $mail->CharSet = 'UTF-8';
	    $mail->SetFrom($opt_smtp_email, $opt_sitename);
	    $mail->Subject = 'NOVA VOZNJA - ' . $pickupdatereturn . ' - ' . $hourreturn . ':' . $minutereturn;
	    $mail->ContentType = 'text/html';
	    $mail->IsHTML(true);

	    $mail->Body = $message;
// you may also use $mail->Body = file_get_contents('your_mail_template.html');

	    $mail->AddAddress($backup_fahrten_email, $backup_fahrten_email);
// you may also use this format $mail->AddAddress ($recipient);

	    if (!$mail->Send()) {

	    } else {

	    }
	}
    }



    if ($rueckfahrt == '1') {
	if ($emailvom == 'OK' && $emailvom == 'OK') {
	    $done = "OK";
	}
    } elseif ($rueckfahrt == '0') {
	if ($emailzum == 'OK') {
	    $done = "OK";
	}
    } else {
	$done = 'ERROR';
    }

    // echo $done;
    if ($done == 'OK') {


	echo json_encode(array('OK'));
    } else {
	$array = array('ERROR');
	echo json_encode($array);
    }
} else {
    $array = array('ERROR');
    echo json_encode($array);
}
?>