<?php
$time_start = microtime(true);
$rootPath = "../../";
error_reporting(E_ALL);
ini_set("display_errors", "Off");

// check whether CATPCHA is on/off, and define function html_escape
require_once $rootPath . "global/inc/html_escape.php";
//$CAPTCHA_ACTIVE = FALSE; // local override

require_once $rootPath . "global/inc/inc_countries.php";
require_once $rootPath . "global/inc/inc_formvalidator.php";
// php.ini Nastavenie upload_max_filesize
function uploadMaxFilesize()
{
    $ret = @ini_get("upload_max_filesize");
    if (!$ret) {
        return "8M";
    }

    return $ret;
}

// Lokalizacie - nastavenie spravneho jazyka
require_once "localization.php";
// Ak nechceme zobrazit KB strom, chceme telefonne cislo alebo len zobrazit custom form - tu sa to definuje
require_once "customForm.php";
// Lokalizacie stromu a formulara
require_once "localization_xml.php";
$formGuardActive = false;
if ($formGuardActive) {
    require_once $rootPath . 'global/inc/FormGuard/formguard.inc.old.php';
    $FormGuard = new FormGuard;
    $FormGuard->ini_session();
}
//if (array_key_exists("language", $_GET) && $_GET['language'] == "cs") die("?");
// Validacie vstupov a pod.
require_once "validate.php";

$status = false;
if (isset($_GET['status']) && in_array($_GET['status'], ['success', 'error', 'form'])) {
    $status = $_GET['status'];
}

// Toto su funkcie na zobrazovanie inputov a inych veci
require_once "functions.php";
// require_once $rootPath."inc/support-contact/inc_buildxml.class.php";
require_once "inc_buildxml.class.php";
// require_once $rootPath."inc/support-contact/form_validate.php";
require_once "form_validate.php";

// Setup empty
$guid = $product_version = $product_version_raw = "";
if (!isset($product)) {
    $product = "";
}
if (!isset($operating_system)) {
    $operating_system = "";
}

if (!isset($displayUsernameField)) {
    $displayUsernameField = true;
} // Always ask for username/publicid except of (see below)
if (!isset($displayAlertSessionExpired)) {
    $displayAlertSessionExpired = true;
}
if (!isset($user_name)) // Maybe defined in form_validate.php
{
    $user_name = "";
}
if (isset($_GET['guid']) && guidIsValid($_GET['guid'])) {
    $guid = $_GET['guid'];
}

if (isset($_GET['utm_source'])){
    $utmsource = $_GET['utm_source'];
}

if (isset($_GET['custom1'])){
    $xCustom1 = $_GET['custom1'];
}

if (isset($_GET['custom2'])){
    $xCustom2 = $_GET['custom2'];
}

if (isset($_GET['username']) && usernameIsValid($_GET['username'])) {
    $user_name = $_GET['username'];
    $displayUsernameField = false;
}
if (isset($_GET['publicid']) && usernameIsValid($_GET['publicid'])) {
    $user_name = $_GET['publicid']; // Merged into one field
    $displayUsernameField = false;
}
// Sometimes we receive either "publicid" or "publicId" :)
if (isset($_GET['publicId']) && usernameIsValid($_GET['publicId'])) {
    $user_name = $_GET['publicId']; // Merged into one field
    $displayUsernameField = false;
}
if (isset($_GET['country']) && countryIsValid($_GET['country']) && empty($_POST['country'])) {
    $country = $_GET['country'];
}
if (isset($_GET['product']) && productIsValid($_GET['product']) && empty($_POST['product'])) {
    $product = $_GET['product'];
}
if (isset($_GET['version']) && versionIsValid($_GET['version'])) {
    $product_version = $_GET['version'];
    $product_version_raw = $product_version; // Version full
    if (!empty($product_version) && strpos($product_version, '.')) {
        $product_version = substr($product_version, 0, strpos($product_version, ".")); // Version major
    }
}
if (isset($_GET['osbuild']) && !empty($_GET['osbuild']) && empty($_POST['operating_system'])) {
    $operating_system = sanitizeString($_GET['osbuild']);
    if ($operating_system == "6.1.7601") {
        $operating_system = "6.1.7600";
    } // W7 SP1
    elseif ($operating_system == "6.0.6002") {
        $operating_system = "6.0.6000";
    } // WVista SP2
    elseif (strpos($operating_system, "10.0") !== false) {
        $operating_system = "10.0";
    } // W10
}
$submit_data = 0; // By default, data are not submitted from a product
if (isset($_GET['submitdata']) && in_array($_GET['submitdata'], [0, 1])) {
    $submit_data = $_GET['submitdata'];
}

// Tabindex do inputov chceme generovat automaticky
$tabIndex = 1;
// GET URL niekedy robime pomocou http_build_query()
$sGet = $_GET;

// Buttons
$completeURL = $_SERVER['REQUEST_URI'] . ((strpos($_SERVER['REQUEST_URI'], '?') !== false) ? "&" : "?");
$dButtons = '
	<a class="button" id="yes-solved" target="_top" href="' . $lang['button-yes-good-url'] . '">' . $lang['button-yes'] . '</a>
	<a class="button red" id="need-help" href="' . $completeURL . 'status=form{productAddition}" style="width: 220px;">' . $lang['button-no'] . '</a>
	<script>$("#yes-solved").click(function () {alert(\'' . $lang['button-yes-good'] . '\');})</script>' . "\n";

//if (isset($error_hash))
//	var_dump($error_hash);

?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>ESET :: Support :: Contact</title>
    <script src="js/gen_validatorv31.js" type="text/javascript"></script>
    <script src="js/ga-track.js" type="text/javascript"></script>
    <script src="js/jquery.min.js" type="text/javascript"></script><!--[if (gte IE 9)|!(IE)]><!-->
    <script type="text/javascript" src="./js/jquery-3.3.1.min.js"></script><!--<![endif]--><!--[if lte IE 8]>
    <script type="text/javascript" src="./js/jquery-1.11.3.min.js"></script><![endif]-->
    <script type="text/javascript" src="js/tooltip.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $('.tooltip').tooltipster({
                contentAsHTML: true,
                arrow: false,
                delay: 100,
                interactive: true,
                interactiveTolerance: 50,
            });
        });
    </script>
    <script src="https://int.form.eset.com/js/countdown.js" type="text/javascript"></script>
    <script type="text/javascript" src="https://int.form.eset.com/js/iframeResizer.contentWindow.min.js"></script>
    <script type="text/javascript" src="js/license.js"></script>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" type="text/css" href="css/global/form-style.css"/>
    <link rel="stylesheet" type="text/css" href="css/global/fg.css"/>
    <link rel="stylesheet" type="text/css" href="css/tooltip.css"/>
    <link rel="stylesheet" type="text/css" href="glyphicons/glyphicons.css"/>
    <!-- <link rel="stylesheet" type="text/css" href="css/form-style.css?20181121"/> -->
    <link rel="stylesheet" type="text/css" href="css/form-style.css"/>
    <!--
    <link rel="stylesheet" type="text/css" href="css/small-device.css" media="only screen and (max-width: 480px), only screen and (max-device-width: 480px)" />
    -->
    <!--[if lt IE 9]>
    <style type="text/css">
        .glyphicon {
            display: none;
            }

        .input, .select, .textarea {
            padding-top: 1px;
            padding-bottom: 4px;
            }

        .attachmentButtonClass {
            padding-top: 4px;
            }

        input.larges {
            background: transparent;
            color: #C0C0C0;
            }
    </style>
    <!--[if lt IE 10]>
    <style type="text/css">
.formDiv {behavior: url("css/pie/PIE.php");}
    </style>
<![endif]-->
    <!--[if lt IE 11]>
    <style type="text/css">
        .fileinputs img {
            margin-left: 8px;
            }

        /* IE does not inherit inputFILE.padding */
    </style>
    <![endif]-->
    <noscript>
        <style type="text/css">
            /* Somehow display placeholder texts and others */
        </style>
    </noscript>
    <?php

    if (isset($googleTagManagerID)) {
    } else {
        $googleTagManagerID = "GTM-T9B2Z5";
    }
    // $googleTagManagerID = "GTM-9QRT";
    // Must be inside <head>
    require_once "google_tag_manager.php";

    // Load KB tree if available
    require_once "KBtree.php";
    $formActive = isset($forceTree) || $solution->getSolution() == "_FORM";

    // Captcha HEAD
    if ($status == "form" || $formActive) { // if form active, load captcha
        $lang_code = convertToCaptchaFormat($langString);
        require_once $rootPath . "global/inc/recaptcha_inc_head.php";
    }

    ?>

</head>
<body>


<?php

// Must be after <body>
require_once "google_tag_manager_body.php";

// Bud zobrazime solution, alebo konkretny KB (pod)strom
if (isset($forceTree)) {
    ;
} else {
    echo '<h1>' . $sTitle . '</h1>' . "\n";
}

require_once "languageDropDown.php";
if (empty($status)) {
    $GTMPushString = '';
    if (preg_match("/^en/", $langString)) {
        $eventGTM = 'SupportFormCustomEvent';
        $evAction = str_replace("&amp;", "&", isset($outArrPlain[1]) ? $outArrPlain[1] : "");
        if (array_key_exists(2, $outArrPlain)) {
            $evLabel = '"' . $outArrPlain[2] . ' > " + $("h1").html()';
        } else {
            $evLabel = '$("h1").html()';
        }
        $GTMPushString = '  <script type="text/javascript">
    SupportFormPathPushArray = {
      event: "' . $eventGTM . '",
      evCategory: "SupportForm_VisitFinalSolution",
      evAction: "' . $evAction . '",
	  evLabel: ' . $evLabel . '
    };
    window.dataLayer.push(SupportFormPathPushArray);
    $("#need-help").click(function() {
     SupportFormPathNeedHelpArray = {
      event: "' . $eventGTM . '",
      evCategory: "SupportForm_NeedHelp",
      evAction: "' . $evAction . '",
	  evLabel: ' . $evLabel . '
     };
     window.dataLayer.push(SupportFormPathNeedHelpArray);
    });
    $("#yes-solved").click(function() {
     SupportFormOKHelpedArray = {
      event: "' . $eventGTM . '",
      evCategory: "SupportForm_OKHelped",
      evAction: "' . $evAction . '",
	  evLabel: ' . $evLabel . '
     };
     window.dataLayer.push(SupportFormOKHelpedArray);
    });
  </script>' . "\n";
    }
    if ($formActive) {
        $status = "form";
    } elseif ($solution->isFinal()) {
        echo '<div class="formDiv">' . "\n";
        echo $navigationHTML;
        echo '<h2>' . $lang['try-this'] . '</h2>' . "\n";
        echo $solution->getSolution();
		$productAddition = "";
		if (!empty($solution->getProduct()) && empty($product))
			$productAddition = "&product=" . $solution->getProduct();
		$dButtons = str_replace("{productAddition}", $productAddition, $dButtons);
        echo $dButtons;
        echo '<div style="clear:both;"></div>' . "\n";
        echo '</div>' . "\n";
        echo $GTMPushString;
    } else {
        echo $navigationHTML;
        for ($i = 0; $i < count($solution->decisionTree); $i++) {
            $sGet['solutionPath'] = implode("-", array_merge($solutionPath, [$i]));
            $sUrl = "./" . "?" . sanitizeString(http_build_query($sGet));
            $sStyle = $solution->decisionTree[$i]->getStyle();
            $sSolution = $solution->decisionTree[$i]->getSolution();
            if ($sSolution == "_FORM")
				$sUrl .= "&status=form";
            echo '<div class="formDiv' . (!empty($sStyle) ? ' ' . $sStyle . '' : "") . '">' . "\n";
            if ($sSolution == "_STOP") {
                echo '<h2>' . $solution->decisionTree[$i]->getName() . '</h2>' . "\n";
            } else {
                echo '<h2><a href="' . $sUrl . '">' . $solution->decisionTree[$i]->getName() . '</a></h2>' . "\n";
            }
            $sDescription = $solution->decisionTree[$i]->getDescription();
            if (!empty($sDescription)) {
                echo '<p>' . $sDescription . '</p>' . "\n";
            }
            echo '</div>' . "\n";
        }
    }
    ?>
    <div style="clear: both;"></div>
    <?php
}
if ($status == 'form') {
    if ($lang_number == 1051 && empty($fType)) {
        echo "<p>" . file_get_contents("data/sk_veta.txt") . "</p>";
    }
    include "../../global/inc/announcement_forms.php";
    ?>
    <?= isset($error_hash['sendFailed']) ? '<p class="err-text-failed">' . $error_hash['sendFailed'] . "</p>\n" : ""; ?>
    <?= isset($error_hash['re_capcha_val']) ? '<p class="err-text-failed">' . (array_key_exists($lang_code,
        $CAPACHA_ERROR) ? $CAPACHA_ERROR[$lang_code][$error_hash["re_capcha_val"]] : $CAPACHA_ERROR['en'][$error_hash["re_capcha_val"]]) . "</p>\n" : ""; ?>
    <?= isset($error_hash['doubleTicketVerification']) ? '<p class="err-text-failed">' . $error_hash['doubleTicketVerification'] . "</p>\n" : ""; ?>
    <form method="post" name="info" action="" enctype="multipart/form-data" class="formDiv">
        <?php
        echo $navigationHTML;
        if ($formGuardActive) {
            echo $FormGuard->get_sid_el();
            echo "\n\n"; // get_sid_el does not return newlines
        }
        if ($displayUsernameField) {
            echo '<fieldset>' . "\n";
            echo '<legend>' . $lang['l-licinfo'] . '</legend>' . "\n";
            echo displayInputElement("user-name", "user_name", isset($user_name) ? $user_name : "",
                ["fullsize" => true, "onchange" => "validateUserName()"]);
            echo '<div id="user_name_alert" style="display:none;">' . $lang['tt-alert-license'] . '<img src="images/LicenseID.png" width="100%"></div></fieldset>' . "\n";
        } else {
            echo '<input type="hidden" name="user_name" value="' . $user_name . '" />' . "\n";
        }
        ?>

	

        <fieldset>
            <legend><?php echo $lang['l-contact']; ?></legend>
            <?php
            echo displayInputElement("first-name", "first_name", isset($first_name) ? $first_name : "");
            echo displayInputElement("last-name", "last_name", isset($last_name) ? $last_name : "",
                ["hideLabel" => true]);
            echo displayInputElement("email", "contact_email", isset($contact_email) ? $contact_email : "");
            echo displayInputElement("confirm-email", "confirm_email", isset($confirm_email) ? $confirm_email : "",
                ["hideLabel" => true]);
            if (isset($hideCompany)) {
                ;
            } else {
                echo displayInputElement("company", "company", isset($company) ? $company : "",
                    ["required" => "-1", "fullsize" => true]);
            }

            if ($displayPhoneNumber) {
                echo displayInputElement("phone", "custom1", isset($phone) ? $phone : "",
                    ["fullsize" => true, "required" => "-1"]);
            }

            if (!isset($allowSelectCountry)) {
                $allowSelectCountry = true;
            }
			if (!isset($countrySelectorForced)) {
                $countrySelectorForced = false;
            }
            if (!empty($lang['_selected_country'])) {
                $countries = explode("|", $lang['_selected_country']);
                if (count($countries) >= 2) {
                    $country_list = $countries;
                } else {
                    $allowSelectCountry = false;
                }
            }
            if ($allowSelectCountry || $countrySelectorForced) {
                $out = "";
                foreach ($country_list as $country) {
                    $out .= sprintf('<option value="%1$s" %2$s>%1$s</option>', $country,
                        (isset($post_country) && $post_country == $country || $lang['_selected_country'] == $country ? 'selected="selected"' : ''));
                }
                echo displaySelectBoxElement("country", "country", $out);
            }
            ?>
        </fieldset>
        <fieldset>
            <legend><?php echo $lang['l-issue']; ?></legend>
            <?php
            /*
            $out = "";
            foreach ($lang['_case_type'] as $key => $value)
                $out .= sprintf('<option value="%s">%s</option>', $key, $value);
            echo displaySelectBoxElement("case-type", "case_type", $out);
            $out = '<option value="other_problem">'.$lang['other-problem'].'</option>'."\n";
            echo displaySelectBoxElement("case-issue", "case_issue", $out, Array("disabled" => TRUE));
            */

            ?>

            <?php
            /* Case Type / Issue */
            if (!isset($forceTree)) {
                echo '<input type="hidden" name="case_type" value="' . $sCaseType . '" />' . "\n";
                echo '<input type="hidden" name="case_issue" value="' . $sCaseIssue . '" />' . "\n";
            } else {
                require_once "caseTypeIssue.php";
                $jsonCases = json_encode($lang['case-issue'], JSON_HEX_APOS | JSON_HEX_QUOT);
                // Unicode hax
                $jsonCases = str_replace("\\", "\\\\", $jsonCases);
                ?>
                <script src="js/caseType.js" type="text/javascript"></script>
                <script type="text/javascript">
                    var case_issues = jQuery.parseJSON('<?=$jsonCases?>');
                </script>
                <?php
                $out = "";
                foreach ($lang['case-type'] as $case => $caseName) {
                    $out .= sprintf('<option value="%1$s">%2$s</option>', $case, $caseName);
                }
                if (isset($hideCaseType)) // Niekedy nechceme zobrazovat case-type
                {
					$outCaseType = "-";
					if (isset($caseType) && !empty($caseType))
						$outCaseType = $caseType;
                    echo '<input type="hidden" name="case_type" value="'. $outCaseType. '" />' . "\n";
                } else {
                    echo displaySelectBoxElement("case-type", "case_type", $out);
                }
                $out = '<option value="other_problem">' . $lang['other-problem'] . '</option>' . "\n";
                if ($fType == "sk-partner") {
                    @$out = stream_get_contents(fopen('./data/case/case_sk_partner.txt', 'r'));
                    echo displaySelectBoxElement("case-issue-kajci", "case_issue", $out, ["disabled" => false]);
                } elseif ($fType == "cz-servis") {
                    @$out = stream_get_contents(fopen('./data/case/case_cs_servis.txt', 'r'));
                    echo displaySelectBoxElement("case-issue-buchtic", "case_issue", $out, ["disabled" => false]);
                } elseif (isset($caseIssue) && !empty($caseIssue) && $caseIssue != "{empty}") {
                    echo '<input type="hidden" name="case_issue" value="' . $caseIssue . '" />' . "\n";
                } elseif (isset($caseIssue) && $caseIssue == "{empty}") {
                    echo '<input type="hidden" name="case_issue" value="" />' . "\n";
                } else {
                    echo displaySelectBoxElement("case-issue", "case_issue", $out, ["disabled" => true]);
                }
            }

            /* Subject */
            if (isset($subjectString) && !isset($subject)) {
                $subject = $subjectString;
            }
            if (isset($subjectModifier) && !isset($subject)) {
                $subject = $lang[$subjectModifier];
            }
            echo displayInputElement("subject", "subject", isset($subject) ? $subject : "",
                ["fullsize" => true, "readonly" => (isset($subjectReadOnly) && $subjectReadOnly === true)]);

            ?>


            <input type="hidden" name="solution_path" value="<?= implode(",", $solutionPath) ?>"/>
            <?php if (isset($passwordreset_unlockCode)) { ?>
                <input type="hidden" name="passwordreset_unlockcode" value="<?= $passwordreset_unlockCode ?>"/>
            <?php } ?>

            <label for="comment" style="padding-top: 12px;"><?php echo $lang['lb-description']; ?></label>
            <div style="display: inline;" class="<?= isset($error_hash['comment']) ? 'td-input-error' : 'td-input'; ?>">
                <textarea class="textarea larger" name="comment" id="comment" rows="5" cols="20"
                          tabindex="<?php echo $tabIndex++; ?>"
                          onkeypress="checkCommentSize(this.value.length, '<?= $lang['val-comment2'] ?>');"><?php if (isset($comment) && !empty($comment)) {
                        echo $comment;
                    } ?></textarea>
                <?php if (isset($error_hash['comment'])) { ?>
                    <span class="err-text tooltip" title="<?= $lang['required']; ?>"><img src="../img/arrow-err.png"
                                                                                          width="4" height="7" alt=""/></span>
                <?php } ?>
                <img class="tooltip opaced" src="images/info-icon-hover.png" alt="?"
                     title="<?php echo sanitizeString($lang['tt-description']); ?>" style="vertical-align: 50px;"/>
            </div>

            <?php if ($displayLogs) { ?>
                <label for="logs" style="color: #fff;"><?php echo $lang['lb-logs']; ?></label>
                <div class="td-input" style="float: left;">
                    <p id="logsInput"><input type="checkbox" name="logs" id="logs" style="border-color: #ccc;" value="1"
                                             onclick="javascript:$('#logsText').css('display', 'block');$('#logsInput').css('display', 'none');"/> <?php echo $lang['lb-logs-extra']; ?>
                    </p>
                    <p id="logsText" style="display: none;"><?php echo $lang['tt-logs']; ?></p>
                </div>
            <?php } ?>

            <label for="supportfile"><?php echo $lang['lb-attachment']; ?></label>
            <div class="td-input tooltip fileinputs">
                <input type="file" class="input filestyle larger" name="supportfile" id="supportfile"
                       tabindex="<?php echo $tabIndex++; ?>"/>
                <img class="tooltip opaced" src="images/info-icon-hover.png" alt="?"
                     title="<?php echo htmlspecialchars($lang['tt-attachment']); ?>"/>
            </div>
            <script type="text/javascript" src="js/filestyle.js"></script>

            <script type="text/javascript">
                function displayVersions(versions) {
                    $("#product_version").empty();
                    $("#product_version").append("<option value=''>-- <?=$lang['select-option']?> --</option>");
                    if (versions == undefined || versions == "") {
                        $("#product_version").prop('disabled', true);
                        $("img.tooltip:last").css("display", "none");
                        return;
                    }
                    $("#product_version").prop('disabled', false);
                    $("img.tooltip:last").css("display", "inline");
                    versions = versions.split(",");
					selectedFromProduct = false;
                    for (i = 0; i < versions.length; i++) {
						ver = versions[i]
						if (versions[i].indexOf(".") < 0)
							ver = ver + ".x";
                        selected = "";
                        if (versions[i] == "<?=$product_version_raw?>") {
                            selected = ' selected="selected"';
							selectedFromProduct = true;
						}
                        if (!selectedFromProduct && versions[i] == "<?=$product_version?>")
                            selected = ' selected="selected"';
                        $("#product_version").append("<option value='" + ver + "'" + selected + ">" + ver + "</option>");
                    }
                }

                function displayProducts(osclass) {
                    if (document.getElementById("operating_system").value == "")
                        return;
                    products = document.getElementById("product");
                    for (i = 0; i < products.length; i++) {
                        osclassLocal = products[i].getAttribute('osclass');
                        if (osclassLocal == osclass || osclassLocal == undefined || osclassLocal == "" || osclassLocal == "all")
                            products[i].style.display = "block";
                        else
                            products[i].style.display = "none";
                    }
                }
            </script>
        </fieldset>
        <?php if (TRUE) { ?>
            <fieldset>
                <legend><?php echo $lang['l-details']; ?></legend>
                <?php
				if (!isset($currentSegmentToDisplaySpecificProducts)) {
					$currentSegmentToDisplaySpecificProducts = "";
					if (isset($dTree)
						&& property_exists($dTree, "decisionTree")
						&& array_key_exists(0, $solutionPath)
					    && isset($dTree->decisionTree[$solutionPath[0]])) {
						$currentSegmentToDisplaySpecificProducts = $dTree->decisionTree[$solutionPath[0]]->getSegment();
					}
                }
                $out = "";
                foreach ($osGroup as $key) {
                    if ($currentSegmentToDisplaySpecificProducts == "business" && $key->category == "home") {
                        continue;
                    } // We do not want "home" here
                    if ($currentSegmentToDisplaySpecificProducts == "home" && $key->category == "business") {
                        continue;
                    } // We do not want "business" here
                    $selectedOS =
                        property_exists($key, "build")
                        && strlen($operating_system) > 0
                        && ($operating_system == $key->build || $operating_system == $key->name);;
                    $out .= sprintf('<option value="%s"' . ($selectedOS ? ' selected="selected"' : "") . ' osclass="%s">%s</option>' . "\n",
                        $key->name, $key->osClass, $key->name);
                }
                $isInternal = !empty($fType) && in_array($fType, ['sk-internal', 'cz-internal']);

                echo displaySelectBoxElement(
                    "operating-system",
                    "operating_system",
                    $out,
                    [
                        "onchange" => "displayProducts(this.options[this.selectedIndex].getAttribute('osclass'))",
                        "required" => $isInternal ? "-1" : "1"
                    ]
                );

                $out = "";
                foreach ($productGroup as $key) {
                    if (!$guid) {
                        if ($key->category == "home" && $currentSegmentToDisplaySpecificProducts == "business") continue;
                        if ($key->category == "business" && $currentSegmentToDisplaySpecificProducts == "home") continue;
                    }
                    $selectedProduct =
                        property_exists($key, "short")
                        && strlen($product) > 0
                        && ($product == $key->short || $product == $key->name);
                    $productVersionsToSelect = implode(",", array_reverse($key->versions));
                    if ($selectedProduct && strpos($product_version_raw, ".")) {
                        $productVersionsToSelect = $product_version_raw . "," . $productVersionsToSelect;
                    }
                    $out .= sprintf(
                        '<option value="%s"%s versions="%s" osclass="%s">%s</option>' . "\n",
                        $key->name,
                        $selectedProduct ? ' selected="selected"' : "",
                        $productVersionsToSelect,
                        $key->osClass,
                        $key->name
                    );
                }

                echo displaySelectBoxElement(
                    "product",
                    "product",
                    $out,
                    [
                        "onchange" => "displayVersions(this.options[this.selectedIndex].getAttribute('versions'))",
                        "required" => $isInternal ? "-1" : "1"
                    ]
                );

                $out = "";

                echo displaySelectBoxElement(
                    "product-version",
                    "product_version",
                    $out,
                    [
                        "disabled" => true,
                        "required" => $isInternal ? "-1" : "1"
                    ]
                );

                ?>
                <div style="clear: both;"></div>
            </fieldset>
        <?php } ?>

        <?php
        if (!$allowSelectCountry) {
            if (isset($selectedCountry)) {
                $lang['_selected_country'] = $selectedCountry;
            }
            printf('<input type="hidden" name="country" value="%s" />' . "\n", $lang['_selected_country']);
        }
        if (!empty($guid)) {
            printf('<input type="hidden" name="guid" value="%s" />' . "\n", $guid);
        }
        ?>
            <?php if (isset($displayMarketingConsent) && $displayMarketingConsent === TRUE) { ?>
                <label for="consent" style="color: #fff;"><?php echo $lang['lb-consent']; ?></label>
                <div class="td-input" style="float: left; width: 420px;">
                    <p id="consentInput"><input type="checkbox" name="consent" id="consent" style="border-color: #ccc;" value="1"><span><?php echo $lang['lb-consent-extra']; ?><br />&nbsp;</span>
                    </p>
                </div>
                <div style="clear: both;"></div>
            <?php } ?>
        <div class="buttonMargin">
            <p style="display: none;"></p>
            <?php
            // Captcha BODY
            if (true) {
                $lang_code = convertToCaptchaFormat($langString);
                require_once $rootPath . "global/inc/recaptcha_inc_body.php";
            }
            ?>
            <input type="submit" name="submit" id="submit_button" class="button"
                   value="<?php echo $lang['submit']; ?>"/>
            <span style="display: none" id="incr">5</span>
        </div>
        <div style="clear: both;"></div>

        <script type="text/javascript">
            if (document.getElementById("product")) {
                displayProducts(document.getElementById("operating_system").options[document.getElementById("operating_system").selectedIndex].getAttribute('osclass'));
                displayVersions(document.getElementById("product").options[document.getElementById("product").selectedIndex].getAttribute('versions'));
            }
            init();
            initFileUploads("<?=$lang['attachment-text']?>", "<?=$lang['attachment-suggestion']?>");
        </script>

        <?php
        // This is a validation for form_validate.php since the submit button not always is a part of _POST
        echo '<input type="hidden" name="form_submit" value="1" />' . "\n";
        ?>

    </form>
    <script type="text/javascript" src="js/placeholderFix.js"></script>
    <script src="js/support-contact-validate.js" type="text/javascript"></script>
    <script type="text/javascript">
        <?php
        for ($i = 0; $i < count($validateFields); $i++) {
            $field = $validateFields[$i][0];

            // When internal (SK or CZ), do NOT add any validation rules for these three
            if (in_array($field, ["operating_system", "product", "product_version"])
                && !empty($fType)
                && in_array($fType, ["sk-internal", "cz-internal"])) {
                continue;
            }

            // Keep the existing guard for fields that may not exist in DOM
            if (in_array($field, ["operating_system", "product"])) {
                echo 'if (document.getElementById("' . $field . '"))' . "\n";
            }

            echo '  frmvalidator.addValidation("' . $field . '","' . $validateFields[$i][1] . '","' . $validateFields[$i][2] . '");' . "\n";
        }
        ?>
        frmvalidator.setAddnlValidationFunction("DoCustomValidation");

        $(function () {
            $('#supportfile').change(function () {
                var f = this.files[0];
                <?php
                $uploadFS = uploadMaxFilesize();
                preg_match('/[0-9]+/', $uploadFS, $uploadFSmatch);
                $uploadFSmatch = $uploadFSmatch[0] * 1024 * 1024;
                ?>
                if (f.size > <?=$uploadFSmatch?> || f.fileSize > <?=$uploadFSmatch?>) {
                    alert("<?php echo $lang['tt-attachment-larger']; ?>");
                    f.value = null;
                }
            })
        });

        var timeoutSession = 1000 * 60 * 45;
        var alertText = "<?=$lang['expired']?>";

        function alertWindow() {
            alert(alertText);
        }

        setTimeout(function () {
            <?=$displayAlertSessionExpired ? 'alertWindow();' . "\n" : "\n"?>
            $("#submit_button").attr('disabled', 'disabled');
            $("#submit_button").css('background', '#888');
            $("#submit_button").css('border-color', '#777');
            $(".buttonMargin p").css('display', 'block');
            $(".buttonMargin p").html(alertText);
        }, timeoutSession);
        $("form.formDiv").submit(function () {
            $("#submit_button").css('background', '#888').css('border-color', '#777');
            $("#submit_button").prop('disabled', true);
            setTimeout(function () {
                $("#submit_button").css('background', '#0096a1 url("./images/bg_send.png") repeat-x');
                $("#submit_button").css('border-color', '#659969');
                $("#submit_button").prop('disabled', false);
            }, 5000);
            //$(this).submit();
            return true;
        });
    </script>

<?php
} elseif ($status == "success") {
?>
    <form method="post" name="info" action="" class="formDiv">
        <table border="0" cellpadding="0" cellspacing="0" class="contact-information-form">
            <tr>
                <td style="width: 480px;">
                    <div><?php echo $lang['status-success']; ?></div>
                </td>
                <td>&nbsp;</td>
            </tr>
        </table>
    </form>
    <?php
}
// require_once "google_analytics.php";
$time_end = microtime(true);
echo "\n<!-- Time: " . round($time_end - $time_start, 3) . " -->";
?>

<div style="clear: both; margin-top: 10px; color: #f4f5f4;">.</div>

</body>
</html>
