<!DOCTYPE html>
<html lang="cs"><head>
        <meta http-equiv="content-type" content="text/html; charset=UTF-8">
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
        <meta name="description" content="Dřevoprodej Zdeněk Beneš">
        <meta name="author" content="Martin Kušnier">

        <title>Prodej řeziva - Zdeněk Beneš</title>

        <!-- Bootstrap core CSS -->
        <link href="./css/bootstrap.css" rel="stylesheet">

        <!-- Custom styles for this template -->
        <link href="./css/starter-template.css" rel="stylesheet">
    </head>

    <body>

        <nav class="navbar navbar-expand-md navbar-dark bg-dark fixed-top moje">
            <div class="collapse navbar-collapse" id="navbarsExampleDefault">
                <ul class="navbar-nav mr-auto">
                    <li class="nav-item">
                        <a class="nav-link" href="./">Domů <span class="sr-only">(current)</span></a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="doprava.html">Doprava</a>
                    </li>
                    <li class="nav-item  active">
                        <a class="nav-link" href="sortiment.php">Sortiment</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="krovy.php">Dodávka krovů</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="kontakt.html">Kontakt</a>
                    </li>
                </ul>
            </div>
            <h1>Prodej řeziva - Zdeněk Beneš</h1>
        </nav>

        <main role="main" class="container">
            <div class="homepage-jumbotron">
                <h2>Náš sortiment</h2>
            </div>

            <hr>
            <p class="sortiment_nadpis">Máme skladem:</p>
            
             <div id="semdej"></div>

            <hr>

            <p class="sortiment_nadpis">
                Nenašli jste, co jste hledali? Využijte kontaktního formuláře a zeptejte se nás.    
            </p>
            <h3 class="sortiment_schovany_nadpis">Individuální objednávka</h3>

            <div class="row">
                <div class="col-2"></div>
                <div class="col-8">
                    <form id="captcha-form" method="post" action="">
                        <div class="form-group">
                            <input type="email" id="mailInput" name="returnAddress" class="form-control" aria-describedby="emailHelp" placeholder="Vaše e-mailová adresa" required>
                        </div>
                        <div class="form-group">
                            <textarea name="mailContent" class="form-control" placeholder="Mam takovou a makovou představu ..."></textarea>
                        </div>
                        
                        <div class="mb-3 d-flex align-items-center">
                            <canvas id="captcha" width="200" height="80"></canvas>
                            <button type="button" class="btn btn-primary" id="refresh-captcha">Obnovit</button>
                        </div>

                        <div class="mb-3">
                            <label for="captcha-input" class="form-label">Opište CAPTCHA kód</label>
                            <input type="text" class="form-control" id="captcha-input" required>
                        </div>
                        <input type="submit" name="sendMail" class="btn btn-primary" value="Odeslat">
                    </form>
                </div>
                <div class="col-2"></div>

            </div>
            <?php

            if($_POST["sendMail"]) {

                $date = date("Y/m/d H:i:s");
                $countryCode = $_SERVER["HTTP_GEOIP_COUNTRY_CODE"];
                $remoteIp = $_SERVER["HTTP_GEOIP_ADDR"];
                //$referer = $_SERVER[""];  Neni vzdy soucasti $_SERVER
                
            
                $resolution = "send";
            
                if(preg_match("/RU|SC|HK|AE/", $countryCode)) {
                    $resolution = "notSend";
                }
                
                $logRecord = $date . " " . $resolution . "\t" . "src:" . $countryCode . ";" . $remoteIp . ";returnAddres:" . $_POST["returnAddress"] . ";msg:" . $_POST["mailContent"] . "\n";
                $f = fopen("log/mail.log", "a");
                fwrite($f, $logRecord);
                fclose($f);

                if($resolution == "send") {

                require "mail.php";
                
                $m = new email();
                $m->reciever = "zdenekbenes@seznam.cz";
                //$m->reciever = "martus9519@seznam.cz";
                $m->sender = "Individuální Objednávka Zboží <postmaster@drevoprodej-benes.cz>";
                $m->cc = array($_POST["returnAddress"], "martus9519@seznam.cz");
                $m->subject = "Individuální Objednávka Zboží";
                $m->content = '
                <!DOCTYPE html>
                <html lang="cs">
                <head>
                    <meta charset="UTF-8">
                    <meta name="viewport" content="width=device-width, initial-scale=1.0">
                    <title>Individuální Objednávka Zboží</title>
                    <style>
                        /* Reset styles */
                        body, h1, p {
                            margin: 0;
                            padding: 0;
                        }
                        body {
                            font-family: Arial, sans-serif;
                            line-height: 1.6;
                            background-color: #f4f4f4;
                        }
                        .container {
                            max-width: 600px;
                            margin: 0 auto;
                            padding: 20px;
                            background-color: #fff;
                            border-radius: 5px;
                            box-shadow: 0 0 10px rgba(0,0,0,0.1);
                        }
                        h1 {
                            color: #333;
                            margin-bottom: 20px;
                        }
                        p, pre {
                            color: #666;
                            margin-bottom: 20px;
                            font-family: arial, sans-serif;
                        }
                        .button {
                            display: inline-block;
                            padding: 10px 20px;
                            background-color: #007bff;
                            color: #fff;
                            text-decoration: none;
                            border-radius: 5px;
                        }
                        .footer {
                            margin-top: 20px;
                            text-align: center;
                            color: #666;
                        }
                    </style>
                </head>
                <body>
                    <div class="container">
                        <h1>Individuální Objednávka Zboží</h1>
                        <pre>' . $_POST["mailContent"] . '</pre>
                        <p>Zprávu odeslal: ' . $_POST["returnAddress"] . '</p>
                    </div>
                    <div class="footer">
                        <p>Tato zpráva byla odeslána z formuláře SORTIMENT</p>
                    </div>
                </body>
                </html>';
                $m->replyTo = $_POST["returnAddress"];
                $m->setHeaders();
                $m->sendMail();
                echo "Email Odeslán.";
                    }

            }

            ?>

            
        </main>

        <script src="js/jquery-3.4.1.js"></script>
        <script>window.jQuery || document.write('<script src="../../../../assets/js/vendor/jquery-slim.min.js"><\/script>')</script>
        <script src="./js/popper.js"></script>
        <script src="./js/bootstrap.js"></script>
        <script src="./js/captcha.js"></script>


        <script src="js/sortiment.js"></script>

    </body></html>
