<?php
error_reporting(E_PARSE && E_ERROR);

session_start();

if ( !isset($_SESSION['csrf']) ) {
	$_SESSION['csrf'] = rand(0, 10000);
}

$page = $_GET['page'];
if (!$page) {
    $page = 'index';
}
$baseUrl = 'http'.((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') || $_SERVER['SERVER_PORT'] == 443 ? 's' : '').'://' . $_SERVER['HTTP_HOST'];
include_once "files/functions.php";

if ( isset($_GET['contact_form']) ) {
	echo '<form method="post" action="">
                    <div class="formularfloat" style="margin-right: 20px;">
                        <div class="textformular">
                            <span>  &#42; </span>
                            FIRST NAME
                        </div>
                        <input class="inputformular" type="text" name="first_name" value="">
                    </div>
                    <div class="formularfloat">
                        <div class="textformular">
                            <span>  &#42; </span>
                            LAST NAME
                        </div>
                        <input class="inputformular" type="text" name="last_name" value="">
                    </div>
                    <div class="clear"> </div>
                    <div class="formularfloat" style="margin-right: 20px;">
                        <div class="textformular">
                            <span>  &#42; </span>
                            EMAIL
                        </div>
                        <input class="inputformular" type="email" name="email" value="">
                    </div>
                    <div class="formularfloat">
                        <div class="textformular">
                            <span>  	 </span>
                            PHONE
                        </div>
                        <input class="inputformular" type="text" name="phone" value="">
                    </div>
                    <div class="clear"> </div>
                    <div class="textformular">
                        <span> &#42; </span>
                        MESSAGE
                    </div>
                    <textarea class="textareaformular" name="message"></textarea>
                    <div class="g-recaptcha" data-sitekey="6Lda5jQUAAAAAGe0iS5s1ga5xKn6VVcg-BUEZ6uD"></div>
                    <button type="submit" class="contactformbutton send-message">SEND</button>
                </form>';
	exit;
}

if (!empty($_POST) && isset($_GET['contact']) && $_GET['contact'] == $_SESSION['csrf'] ) {
    include_once "files/PHPMailer/class.phpmailer.php";
    include_once "files/PHPMailer/class.smtp.php";
    $post = array();
    foreach ($_POST as $key => $value) {
        $post[$key] = escape(strip_tags(htmlentities($value)));
    }

    extract($post);

    $ok = true;
    if (!$first_name || !$last_name || !$email || !$message) {
        $ok = false;
        echo "Please fill all the required fields.";
        exit;
    }

    if ($ok) {
        $subject = "A message from " . $first_name . " " . $last_name . " @ planetweb.ro";
        $to = "robert@planetweb.ro";
        $message = 'A message from ' . $first_name . ' ' . $last_name . ' (email: ' . $email . '), (phone: ' . $phone . ') <br/><br/>Message:<br/>' . $message;
        $ok = sendMail($to, $subject, $message);

        echo 'Thank you for your message!';
        exit;
    }
}

$pages = array('index', 'about-us', 'technologies', 'services', 'portfolio', 'contact', 'game');
$pageDetails = array(
    'index' => array(
        'title' => 'Welcome',
        'keywords' => 'planetweb.ro web development and web design, planetweb.ro, web development, web design, planetweb.ro web dev and design, planetweb.ro development firm, phalcon, zend frameword, zend, mysql, javascript, jquery, mysql, html, html5, css',
        'description' => 'Planetweb.ro Web development and Web design Company, Romania, Craiova. We work mostly in Phalcon and Zend framework.',
        'og:image' => '',
        'og:image:type' => 'image/jpeg',
        'og:title' => '',
        'og:description' => '',
        'og:url' => '',
    ),
    'about-us' => array(
        'title' => 'About us, who we are',
        'keywords' => 'planetweb.ro web development and web design, planetweb.ro, web development, web design, planetweb.ro web dev and design, planetweb.ro development firm, phalcon, zend frameword, zend, mysql, javascript, jquery, mysql, html, html5, css',
        'description' => 'Planetweb.ro Web development and Web design Company, Romania, Craiova. We work mostly in Phalcon and Zend framework.'
    ),
    'technologies' => array(
        'title' => 'Technologies we use',
        'keywords' => 'planetweb.ro web development and web design, planetweb.ro, web development, web design, planetweb.ro web dev and design, planetweb.ro development firm, phalcon, zend frameword, zend, mysql, javascript, jquery, mysql, html, html5, css',
        'description' => 'Planetweb.ro Web development and Web design Company, Romania, Craiova. We work mostly in Phalcon and Zend framework.'
    ),
    'services' => array(
        'title' => 'Services we provide',
        'keywords' => 'planetweb.ro web development and web design, planetweb.ro, web development, web design, planetweb.ro web dev and design, planetweb.ro development firm, phalcon, zend frameword, zend, mysql, javascript, jquery, mysql, html, html5, css',
        'description' => 'Planetweb.ro Web development and Web design Company, Romania, Craiova. We work mostly in Phalcon and Zend framework.'
    ),
    'portfolio' => array(
        'title' => 'Our portfolio',
        'keywords' => 'planetweb.ro web development and web design, planetweb.ro, web development, web design, planetweb.ro web dev and design, planetweb.ro development firm, phalcon, zend frameword, zend, mysql, javascript, jquery, mysql, html, html5, css',
        'description' => 'Planetweb.ro Web development and Web design Company, Romania, Craiova. We work mostly in Phalcon and Zend framework.'
    ),
    'contact' => array(
        'title' => 'Contact us',
        'keywords' => 'planetweb.ro web development and web design, planetweb.ro, web development, web design, planetweb.ro web dev and design, planetweb.ro development firm, phalcon, zend frameword, zend, mysql, javascript, jquery, mysql, html, html5, css',
        'description' => 'Planetweb.ro Web development and Web design Company, Romania, Craiova. We work mostly in Phalcon and Zend framework.'
    ),
);
include_once "files/header.phtml";



if (!in_array($page, $pages)) {
    http_response_code(404);
    include_once "pages/error.phtml";
}

if (!file_exists("pages/" . $page . ".phtml")) {
    http_response_code(404);
    include_once "pages/error.phtml";
}

include_once "pages/" . $page . ".phtml";

include_once "files/footer.phtml";
