<?
$translation = \DynCom\mysyde\common\classes\Registry::get("translation");

if ( isset($_REQUEST["save"])) {
    save();
}

function save() {

/*
    $passwordOptions = get_password_options();
    $hashedPasswordsWebkey = password_hash(filter_input(INPUT_POST,'input_websiteKey'),PASSWORD_DEFAULT,$passwordOptions);
    $hashedPasswordsSecretkey = password_hash(filter_input(INPUT_POST,'input_secretKey'),PASSWORD_DEFAULT,$passwordOptions);

    $query = "UPDATE google_recaptcha SET 
    websitekey = '" . $hashedPasswordsWebkey . "', 
    secretkey =  '" . $hashedPasswordsSecretkey . "'
    WHERE id = 0 LIMIT 1";
*/

    //Prüfen der Key
    $secretKey = '';
    
    $query          = "SELECT * FROM google_recaptcha";
    $result         = @mysqli_query($GLOBALS['mysql_con'], $query);
    $websiteKey = $_POST['websiteKey'];
    $secretKey  = $_POST['secretKey'];
   
    if(@mysqli_num_rows($result) > 0){
        $reCaptcha      = @mysqli_fetch_array($result);
         
        $query = "UPDATE google_recaptcha SET websitekey = '".$websiteKey."', secretkey = '".$secretKey."' WHERE id = ".$reCaptcha['id'];
   
    }else{
        
        $query = "INSERT INTO google_recaptcha (websitekey, secretkey) VALUES (
                '".$websiteKey."',".
                "'".$secretKey."')";  
    }
     
    $result = @mysqli_query($GLOBALS['mysql_con'], $query);
    $responseKey = $_POST['g-recaptcha-response'];
    
    
    echo $responseKey;

}


$messages = array();
$error    = FALSE;

$translation = \DynCom\mysyde\common\classes\Registry::get("translation");
$formname    = "form_recaptcha";

?>

<ul class="toolbar_menu">
    <?= button("save", $translation->get("save"), $formname, " document.getElementById('".$formname."').submit()"); ?>
</ul>

<div id="mainContent">
    <?php echo current_website_language($site, $language); ?>
    <h1><?php echo get_translation('recaptcha'); ?></h1>
    <?php 
        $query          = "SELECT * FROM google_recaptcha";
        $result         = @mysqli_query($GLOBALS['mysql_con'], $query);
        $secretkey = '6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe';
        $websitekey = '6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI';
        $reCaptcha = '';
        if(@mysqli_num_rows($result) > 0){
            $reCaptcha = @mysqli_fetch_array($result);
            $secretkey = $reCaptcha['secretkey'];
            $websitekey = $reCaptcha['websitekey'];
        }
    ?>

    <form id="<?= $formname ?>" name="<?= $formname ?>" method="post" enctype="multipart/form-data">
        <h2>GEHEIMEN SCHLÜSSEL
            
        </h2>
        <input type="text" class="recaptcha" id="recaptcha" name="secretKey" value="<?= $secretkey ;?>"></input>
        
        <h2>WEBSITESCHLÜSSEL</h2>
        <input type="text" class="recaptcha" id="recaptcha" name="websiteKey" value="<?= $websitekey ;?>"></input><br><br>

        <input type="submit" class="button_save" id="save_recaptcha" name="save" value = "<? echo get_translation("save_recaptcha_data") ?>">  </input>

    </form>

</div>