<?php require_once 'protect.php'; ?>
<?php
$itid = $mysqli->real_escape_string(stripslashes($_REQUEST['itid']));
if ($itid) {
$result = $mysqli->query("SELECT * FROM items WHERE page_id='$itid' AND lang_id=$lang");
$row = $result->fetch_array(); 
$id=$row['insert_id'];
$pageid=$row['page_id'];
$pageitem=$row['page'];
if ($itempage==1) { $siteitem=$pageitem; }
$pagesiteitem=$siteitem.".".$pageid;
$item=$row['name'];
$price=$row['price'];
$price1=$row['price'];
$offerprice=$row['offerprice'];
$image=$row['image'];
$days=$row['weight'];
$adays = intval($days);

if ($offerprice=='0.00') { 
$endprice=$price;
}else{
$endprice=$offerprice;
}
}
?>
<?php
if (isset($_POST['submit'])) {
$name = $mysqli->real_escape_string(strip_tags($_REQUEST['name']));
$name = mb_convert_case($name, MB_CASE_TITLE, "UTF-8");
$country = $mysqli->real_escape_string(strip_tags($_REQUEST['country']));
$country = mb_convert_case($country, MB_CASE_TITLE, "UTF-8");
$telephone = $mysqli->real_escape_string(strip_tags($_REQUEST['telephone']));
$fax = $mysqli->real_escape_string(strip_tags($_REQUEST['fax']));
$email = $mysqli->real_escape_string(strip_tags($_REQUEST['email']));
$email = strtolower($email);
$item = $mysqli->real_escape_string(strip_tags($_REQUEST['item']));
$startdate = $mysqli->real_escape_string(strip_tags($_REQUEST['startdate']));
$startdate1 = $mysqli->real_escape_string(strip_tags($_REQUEST['startdate']));
$enddate = $mysqli->real_escape_string(strip_tags($_REQUEST['enddate']));
$enddate1 = $mysqli->real_escape_string(strip_tags($_REQUEST['enddate']));
$adults = $mysqli->real_escape_string(strip_tags($_REQUEST['adults']));
$children = $mysqli->real_escape_string(strip_tags($_REQUEST['children']));
$age = $mysqli->real_escape_string(strip_tags($_REQUEST['age']));
$comments = $mysqli->real_escape_string(strip_tags($_REQUEST['comments']));
$comments = str_replace('\r\n', ' ',$comments);
$comments = preg_replace('/\s+/', ' ',$comments);

if ($adults=='') { $adults='1'; }
if ($children=='') { $children='0'; }

if ($_REQUEST['notes']=='' AND $_REQUEST['data']==$_POST['code1']) {

// calc nr days
if ($adays>0) { 
$enddate = date('Y-m-d', strtotime($startdate . "+".$adays." days"));
$enddate1 = date('d-m-Y', strtotime($startdate . "+".$adays." days"));
}
$timediff = abs(strtotime($startdate) - strtotime($enddate));
$totaldays = $timediff/86400; 
$totaldays = intval($totaldays);
?>
<div class="example2 margbottom10"><?php echo $textorder ?></div>
<?php
if ($id AND $rowspr>0) { 
include 'calcdays.php';
}

if ($endprice AND $endprice!='0.00' AND $rowspr==0) {
$dprice = $endprice-($endprice*(($discount+$langdiscount)/100));
$dprice2 = $dprice-($dprice*($sitediscount2/100));

if ($adays>0) { 
$totalprice += $dprice;
$totalprice2 += $dprice2;
} else {
$totalprice += $dprice*$totaldays;
$totalprice2 += $dprice2*$totaldays;
}

$totalpricep = floor($totalprice);
$totalpricec = floor($totalprice2);

$totalpricef = ($totalpricep*$adults)+($totalpricec*$children);
$amount = $totalpricef;
}

if ($totalpricef>0) {
$subject="Order $domain";
$formprice="$totalpricef Euro";

$result7 = $mysqli->query("SELECT id FROM requests ORDER BY id desc LIMIT 1");
$row=mysqli_fetch_array($result7);
$lastid=$row['id'];
$nextid=$lastid + 1;
$orderid1 = $nextid.date("dmY");

$mysqli->query("INSERT INTO requests (orderid, cookie_id, member_id, item_id, name, email, address, country, tel, items, comments, amount, currency, paytype, url) VALUES ('$orderid1', '$cookieid', '$memberid', '$id', '$name', '$email', '$address', '$country', '$telephone', '$item', '$comments', '$amount', 'EUR', '$paytype', '$pagepath')");

$result8 = $mysqli->query("SELECT orderid FROM requests ORDER BY id desc LIMIT 1");
$row=mysqli_fetch_array($result8);
$orderid=$row['orderid'];
} else {
include 'req.php';
$subject="Request $domain";
}

$to="$email";
if ($itemail) { 
$bcc="$itemail, $sitemail";
} else {
$bcc="$sitemail";
}
$from="$email";
$reply="$email";
$headers="MIME-Version: 1.0\r\n";
$headers .="Content-type: text/plain; charset=utf-8\r\n";
$headers .="Bcc: $bcc\r\nFrom: $from\r\nReply-To: $reply";
$subject="$subject";

$message="$subject
______________________________________________________________________________________

$fieldname: $name 
$fieldcountry: $country
Tel: $telephone
Fax: $fax
Email: $email
$fieldsubject: $item $code
$fielddates: $startdate1 - $enddate1
$fieldres1: $adults
$fieldres2: $children
$fieldage: $age
$fieldcomments: $comments
______________________________________________________________________________________
$formprice

www.$domain  
";
mail ($to, $subject, $message, $headers);
?>
<div>
<?php echo $fieldname ?>: <?php echo $name ?> <br>
<?php echo $fieldcountry ?>: <?php echo $country ?> <br>
<?php echo $fieldtel ?>: <?php echo $telephone ?> <br>
Fax: <?php echo $fax ?> <br>
Email: <?php echo $email ?> <br>
<?php echo $fieldcomments ?>: <?php echo $comments ?>
<hr>
<div class="titles"><?php echo $item ?> </div>
<hr>
<?php echo $textdays ?>: <strong><?php echo $totaldays ?></strong> <br>
<?php echo $fielddates ?>: <strong><?php echo $startdate1 ?> <?php if ($adays!=1) {  echo "&raquo; ".$enddate1; } ?></strong> <br>
<?php echo $fieldadults ?>: <strong><?php echo $adults ?></strong> <?php if ($totalpricef>0) { ?><span class="price"><?php echo ($totalpricep*$adults); ?> &#8364;</span><?php } ?>  <br>
<?php echo $fieldchildren ?>: <strong><?php echo $children ?></strong> <?php if ($totalpricef>0) { ?><span class="price"><?php echo ($totalpricec*$children); ?> &#8364;</span><?php } ?>
<hr>
<?php if ($totalpricef>0) { ?>
<span class="titles"><?php echo $texttotal ?> <?php echo $textprice ?></span> <span class="price"><?php echo $totalpricef ?> &#8364;</span><br>
<?php } ?>
</div>
<?php if ($payment==1 AND ( ($endprice AND $endprice!='0.00' AND $rowspr==0) OR ($totalpricef>0 AND ($adays>0 OR $allprice>0)) ) ) { ?>
<?php include 'payment.php';?>
<?php } ?>
<!--end submit -->
<?php } else { ?>
<a href="javascript:history.go(-1);"><?php echo $fieldtext2 ?></a>
<?php } ?>
<?php } else { ?>   
<form name="forma" method="post">	
<div class="divfloat1 margbottom20">
<div class="titles"><?php echo $fielddetails ?></div> <hr>

<div><label for="name" class="hiddenlabel"><?php echo $fieldname ?>*</label> <input type="text" name="name" id="name" placeholder="<?php echo $fieldname ?>*" size="20" maxlength="50" required></div>
<div><label for="country" class="hiddenlabel"><?php echo $fieldcountry ?></label> <input type="text" name="country" id="country" placeholder="<?php echo $fieldcountry ?>" size="20" maxlength="50"></div>
<div><label for="telephone" class="hiddenlabel"><?php echo $fieldtel ?>*</label> <input type="text" name="telephone" id="telephone" placeholder="<?php echo $fieldtel?>*" size="20" maxlength="50" required></div>
<div><label for="fax" class="hiddenlabel">Fax</label> <input type="text" name="fax" id="fax" placeholder="Fax" size="20" maxlength="50"></div>
<div><label for="email" class="hiddenlabel">Email*</label> <input type="email" name="email" id="email" placeholder="Email*" size="20" maxlength="60" required></div>

</div>
<div class="divfloat2">
<div class="titles"><?php echo $fieldrequest ?></div><hr>
<div>
<?php if ($pagename=='item.php'){ ?>
<strong><?php echo $item ?></strong>
<input type="hidden" name="item" value="<?php echo $item ?>">
<?php }else{?>
<label>
<select name="item" id="item">
<?php 
$result = $mysqli->query("SELECT * FROM items WHERE available=1 AND lang_id=$lang AND publish='yes' ORDER BY category_id, priority");
while($row = $result->fetch_array()) {	
$itemid=$row['insert_id'];
$item=$row['name'];
?>
<option value="<?php echo $item ?>"<?php if ($itemid==$id) { echo " selected"; }?>> 
<?php echo $item ?>
</option>
<?php }?>
<option value="<?php echo $requestoption ?>"><?php echo $requestoption ?></option>
</select>
</label>
<?php } ?>
</div>
<div>
<label for="startdate" class="hiddenlabel"><?php echo $checkin ?></label> <input type="text" name="startdate" id="startdate" placeholder="<?php echo $checkin ?>" size="10" maxlength="10" class="inputauto calendar" required>
<label for="enddate" class="hiddenlabel"><?php echo $checkout ?></label> <input type="text" name="enddate" id="enddate" placeholder="<?php echo $checkout ?>" size="10" maxlength="10" class="inputauto calendar" required></div>
<div>
<label for="adults" class="hiddenlabel"><?php echo $fieldadults ?></label> <input type="text" name="adults" id="adults" placeholder="<?php echo $fieldadults ?>" size="10" maxlength="50" class="inputauto" required>
<label for="children" class="hiddenlabel"><?php echo $fieldchildren ?></label> <input type="text" name="children" id="children" placeholder="<?php echo $fieldchildren ?>" size="10" maxlength="50" class="inputauto formchildren">
<label for="age" class="hiddenlabel"><?php echo $fieldage ?></label> <input type="text" name="age" id="age" placeholder="<?php echo $fieldage ?>" size="10" maxlength="10" class="inputauto formage">
</div>
<div><label for="comments" class="hiddenlabel"><?php echo $fieldcomments ?></label> <textarea name="comments" id="comments" placeholder="<?php echo $fieldcomments ?>" rows="4" cols="30"></textarea></div>
<div>
<label for="code1" class="hiddenlabel"><?php echo $fieldcode ?></label>
<?
global $data;
$data = mt_rand(100000,1000000);
?>
<input type="hidden" name="code1" value="<?php echo $code1 ?>">
<input type="hidden" name="data" value="<?php echo $data ?>"> 
<img src="<?php echo $sitepath ?>includes/dynamicimage.php?dt=<? global $data; echo base64_encode($data);?>" alt="">
<input type="text" name="code1" id="code1" placeholder="<?php echo $fieldcode ?>" size="16" maxlength="6" class="inputcode" required>
<label class="hide">note<input type="text" name="notes" id="notes" size="1" maxlength="20" class="fieldnotes"></label>
</div>

<div class="divsubmit"><input type="submit" name="submit" class="button buttonsubmit" value="<?php echo $button1 ?>"></div>
<div class="divrequired color2">* <?php echo $fieldrequired ?></div>
</div>
</form>
<?php } ?>
<div class="cleared"></div>