<?php
includeContainer('_library_lib.php', 1);
setSessionLang();
$socInfo = getSocInfo();

if (GETPOST('action') == 'sendmail') {
    include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
    
    // Set message language
	$emaillang = new Translate('', $conf);
	if ($mysoc->default_lang) {
	    $emaillang->setDefaultLang($mysoc->default_lang);
	    $emaillang->loadLangs(array("main", "website"));
	}
	

    $from = GETPOST('email', 'alpha');
    $to = $mysoc->email;
    $subject = html_entity_decode ($emaillang->trans("contactFormReceived", $website->ref));

    $firstname = GETPOST('firstname', 'alpha');
    $phone = GETPOST('phone', 'alpha');
    $usersubject = GETPOST('subject', 'alpha');
    $messageContent = GETPOST('message', 'alpha');

    $message = html_entity_decode ($emaillang->trans("contactFormReceived", $website->ref)) . "\n\n";
    $message .= html_entity_decode ($emaillang->trans("contactFormName")) . ": $firstname\n";
    $message .= html_entity_decode ($emaillang->trans("contactFormEmail")) . ": $from\n";
    $message .= html_entity_decode ($emaillang->trans("contactFormPhone")) . ": " . (!empty($phone) ? $phone : "N/A") . "\n";
    $message .= html_entity_decode ($emaillang->trans("contactFormSubjectEntered")) . ": $usersubject\n\n";
    $message .= html_entity_decode ($emaillang->trans("contactFormMessageLabel")) . ":\n$messageContent\n";

    $cmail = new CMailFile($subject, $to, $from, $message);

    if ($cmail->sendfile()) {
        ?>
        <script>
            alert("<?php echo html_entity_decode ($emaillang->trans("contactFormSuccessAlert")); ?>");
        </script>
        <?php
    } else {
        echo html_entity_decode ($langs->trans("ErrorFailedToSendMail", $from, $to)) . '. ' . $cmail->error;
    }
}



?>
<div class="container-fluid">
    <div class="container py-5">
        
        <div class="container-fluid contact py-5">
            <div class="row g-4">
                <div class="col-xl-5">
                    
                    <div class="section-title" id="section-contact" style="scroll-margin-top: 130px;">
                      <div class="line left-line"></div>
                      <h1><?php echo $weblangs->trans("contactTitle"); ?></h1>
                      <div class="line right-line"></div>
                    </div>
        
                    <p class="mb-4"><?php echo $weblangs->trans("contactMessage"); ?></p>
                    <form method="post" action="#">
                        <div class="row gx-4 gy-3">
                            <div class="col-xl-6">
                                <input type="text" name="firstname" class="form-control bg-white border-0 py-3 px-4" placeholder="<?php echo $weblangs->trans("labelFirstName"); ?>" required>
                            </div>
                            <div class="col-xl-6">
                                <input type="email" name="email" class="form-control bg-white border-0 py-3 px-4" placeholder="<?php echo $weblangs->trans("labelEmail"); ?>" required>
                            </div>
                            <div class="col-xl-6">
                                <input type="text" name="phone" class="form-control bg-white border-0 py-3 px-4" placeholder="<?php echo $weblangs->trans("labelPhone"); ?>">
                            </div>
                            <div class="col-xl-6">
                                <input type="text" name="subject" class="form-control bg-white border-0 py-3 px-4" placeholder="<?php echo $weblangs->trans("labelSubject"); ?>" required>
                            </div>
                            <div class="col-12">
                                <textarea name="message" class="form-control bg-white border-0 py-3 px-4" rows="7" cols="10" placeholder="<?php echo $weblangs->trans("labelMessage"); ?>" required></textarea>
                            </div>
                            <div class="col-12">
                                <button class="btn flat-button text-white py-2 px-3 float-end" type="submit" name="action" value="sendmail"><?php echo $weblangs->trans("submit"); ?></button>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="col-xl-7">
                    <div>
                        <div class="row g-4">
                            <div class="col-lg-6">
                                <div class="bg-white p-2 text-center">
                                    <i class="fas fa-map-marker-alt fa-2x secondary-color mb-2"></i>
                                    <h4><?php echo $weblangs->trans("labelAddress"); ?></h4>
                                    <p class="mb-0"><?php echo $socInfo['address']; ?></p>
                                </div>
                            </div>
                            <div class="col-lg-6">
                                <div class="bg-white p-2 text-center">
                                    <i class="fas fa-envelope fa-2x secondary-color mb-2"></i>
                                    <h4><?php echo $weblangs->trans("labelEmail"); ?></h4>
                                    <p class="mb-0">
                                        <a href="mailto:<?php echo htmlspecialchars($socInfo['email']); ?>">
                                            <?php echo htmlspecialchars($socInfo['email']); ?>
                                        </a>
                                    </p>
                                </div>
                            </div>
                            <!--<div class="col-lg-4">
                                <div class="bg-white p-2 text-center">
                                    <i class="fa fa-phone-alt fa-2x secondary-color mb-2"></i>
                                    <h4><?php echo $weblangs->trans("labelPhone"); ?></h4>
                                    <p class="mb-0"><?php echo $socInfo['phone']; ?></p>
                                </div>
                            </div>-->
                            <div class="col-lg-12">
                                <iframe class="w-100" style="height: 412px; margin-bottom: -6px;" src="https://maps.google.com/maps?q=<?php echo urlencode($mysoc->getFullAddress()); ?>&t=&z=13&ie=UTF8&iwloc=&output=embed" 
                                    loading="lazy" referrerpolicy="no-referrer-when-downgrade"></iframe>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>