<?php require_once 'protect.php'; ?>
<?php
$item = $mysqli->real_escape_string(stripslashes($_REQUEST['item']));
$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'];
$code=$row['code'];
$price=$row['price'];
$price1=$row['price'];
$offerprice=$row['offerprice'];
$image=$row['image'];
$publish=$row['publish'];
}
?>
<div class="divfloat1 margbottom20">
<?php if ($id) { ?>
<div class="titles margbottom20"><?php if ($publish=='yes') { ?><a href="<?php echo $pagesiteitem ?>" class="titles"><?php echo $item ?></a><?php }else{?><?php echo $item ?><?php } ?></div>
<?php if ($pagename!='item.php') { ?>
<?php if ($image==1) { ?>
<?php if ($publish=='yes') { ?>
<a href="<?php echo $pagesiteitem ?>"><img src="<?php echo $codepath ?>includes/image.php?image=<?php echo $imagepath ?>items/<?php echo $id ?>.jpg&amp;nwidth=150" alt="<?php echo $item ?>" title="<?php echo $item ?>"></a>
<?php }else{?> 
<img src="<?php echo $codepath ?>includes/image.php?image=<?php echo $imagepath ?>items/<?php echo $id ?>.jpg&amp;nwidth=150" alt="<?php echo $item ?>" title="<?php echo $item ?>">
<?php } ?>
<?php } ?>
<?php include 'itemprice.php'; ?>
<?php } ?>
<div class="padtop20"><?php echo $textcontact1 ?> <?php echo $textcontactitem ?></div>
<hr>
<?php }else{?> 
<div class="titles"><?php echo $textcontact ?></div> 
<div>
<?php echo $siteaddress ?> <br>
Email: <a href="mailto:<?php echo $sitemail?>?subject=<?php echo $firma ?>"><?php echo $sitemail?></a> 
</div>
<hr>
<?php echo $textcontact1 ?> <?php echo $mapcontact ?>
<?php } ?>
</div>

<?php
if (isset($_POST['submit'])) {
$name = $mysqli->real_escape_string(strip_tags($_REQUEST['name']));
$name = mb_convert_case($name, MB_CASE_TITLE, "UTF-8");
$name = preg_replace('/\s+/', ' ',$name);
$address = $mysqli->real_escape_string(strip_tags($_REQUEST['address']));
$address = mb_convert_case($address, 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']));
$email = $mysqli->real_escape_string(strip_tags($_REQUEST['email']));
$email = strtolower($email);
$email = preg_replace('/\s+/', '',$email);
$item = $mysqli->real_escape_string(strip_tags($_REQUEST['item']));
$quantity = $mysqli->real_escape_string(strip_tags($_REQUEST['quantity']));
if ($amount AND $quantity) { 
$totalamount=$endprice*$quantity;
}
$comments = $mysqli->real_escape_string(strip_tags($_REQUEST['comments']));
$comments = str_replace('\r\n', ' ',$comments);
$comments = preg_replace('/\s+/', ' ',$comments);

if ($_REQUEST['notes']=='' AND $name!=' ' AND $name!='' AND (filter_var($email, FILTER_VALIDATE_EMAIL)) AND $_REQUEST['data']==$_POST['code1']) {

if ($endprice!='0.00' AND $amount) {

$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', '$totalamount', 'EUR', '$paytype', '$pagepath')");

$result8 = $mysqli->query("SELECT orderid FROM requests ORDER BY id desc LIMIT 1");
$row=mysqli_fetch_array($result8);
$orderid=$row['orderid'];

$subject="Order $orderid $domain";
$formprice="Euro";
$formquantity="Quantity";

} else {
include 'req.php';
if ($id) {
$subject="Inquiry $domain";
$amount="";
} else { 
$subject="Message $domain";
}
}

if ($endprice!='0.00' AND $amount) { 
$to="$email";
$bcc="$sitemail";
} else {
$to="$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
$fieldaddress: $address
$fieldcountry: $country
Tel: $telephone
Email: $email
$fieldsubject: $item $code
$fieldcomments: $comments
______________________________________________________________________________________
$amount $formprice
$formquantity $quantity
$totalamount $formprice

www.$domain
";
mail ($to, $subject, $message, $headers);
?>
<div class="cleared example2 margbottom10"><?php echo $fieldtext1 ?></div>
<div>
<?php echo $fieldname ?>: <?php echo $name ?> <br>
<?php echo $fieldcountry ?>: <?php echo $country ?> <br>
<?php echo $fieldaddress ?>: <?php echo $address ?> <br>
<?php echo $fieldtel ?>: <?php echo $telephone ?> <br>
Email: <?php echo $email ?><br>
<?php echo $fieldsubject ?>: <?php echo $item ?><br>
<?php echo $fieldmessage ?>: <?php echo $comments ?>
</div>
<?php if ($payment==1 AND $endprice!='0.00' AND $amount) { ?><?php include 'payment.php';?><?php } ?>
<!--end submit -->

<?php } else { ?>
<a href="javascript:history.go(-1);"><?php echo $fieldtext2 ?></a>
<?php } ?>
<?php } else { ?> 

<?php if ($sitemail) { ?>
<div class="divfloat2">
<form name="forma" method="post">

<div><label for="name" class="hlabel"><?php echo $fieldname ?>*</label> <input type="text" name="name" id="name" placeholder="<?php echo $fieldname ?>*" size="30" maxlength="50" required></div>
<div><label for="address" class="hlabel"><?php echo $fieldaddress ?></label> <input type="text" name="address" id="address" placeholder="<?php echo $fieldaddress ?>" size="30" maxlength="50"></div>
<div><label for="country" class="hlabel"><?php echo $fieldcountry ?></label> <input type="text" name="country" id="country" placeholder="<?php echo $fieldcountry ?>" size="30" maxlength="50"></div>
<div><label for="telephone" class="hlabel"><?php echo $fieldtel ?></label> <input type="text" name="telephone" id="telephone" placeholder="<?php echo $fieldtel ?>" size="30" maxlength="50"></div>
<div><label for="email" class="hlabel">Email*</label> <input type="email" name="email" id="email" placeholder="Email*" size="30" maxlength="60" required></div>
<div><label for="item" class="hlabel"><?php echo $fieldsubject ?></label> <input type="text" name="item" id="item" value="<?php echo $item ?><?php if ($code) { echo ' &raquo; '.$code; } ?>" placeholder="<?php echo $fieldsubject ?>" size="30" maxlength="60">
<?php if ($endprice!='0.00' AND $amount) { ?><input name="quantity" type="text" value="1" size="4" maxlength="11" title="<?php echo $textquantity ?>" class="inputssmall formq"><?php } ?>
</div>
<div><label for="comments" class="hlabel"><?php echo $fieldmessage ?></label> <textarea name="comments" id="comments" placeholder="<?php echo $fieldmessage ?>" rows="8" cols="30"></textarea></div>
<div>
<?
global $data;
$data = mt_rand(100000,1000000);
?>
<label for="code1" class="hlabel"><?php echo $fieldcode ?></label>
<input type="hidden" name="code1" value="<?php echo $code1 ?>">
<input type="hidden" name="data" value="<?php echo $data ?>"> 
<img src="<?php echo $codepath ?>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="formsn"></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>
</form>
</div>
<?php } ?>

<?php } ?><div class="cleared"></div>