<?php 
$jsondata = file_get_contents("./api/main.json");
$data = json_decode($jsondata, true);
$json = $data['app'];
$message = '<div class="alert alert-success" id="flash-msg"><h4><i class="icon fa fa-check"></i>Items Updated!</h4></div>';
if(isset($_POST['submit'])){
$jsonData = file_get_contents("./api/main.json");

$arrayData = json_decode($jsonData, true);
	$replacementData = array('app' =>  array(
	'language'		=>	$_POST["language"],
	'app_language'		=>	$_POST["app_language"]));
$newArrayData = array_replace_recursive($arrayData, $replacementData);
$newJsonData = json_encode($newArrayData, JSON_UNESCAPED_UNICODE);
file_put_contents("./api/main.json", $newJsonData);
header("Location: language.php?message=$message");
		}
include ('includes/header.php');
?>

 
<div class="card mt-3">
  <div class="card-header">
        <i class="fa fa-language"></i> Mudanças de idioma
           </div>
            <div class="card-body">
                
                    <div class="row">
                        <div class="col-12 text-center">
                            <h5> Idioma disponível</h5>
                        </div>
                        <div class="col-md-8 mx-auto">
                            <form method="post">
							<div class="form-group ">
                                    <label class="control-label requiredField" for="app_language" >
                                        <strong> Escolha o idioma do seu aplicativo</strong>
                                    </label>
                                    <select class="select form-control " id="select" name="app_language">
									    <option value="en"<?=$json['app_language']=='en'?'selected':'' ?>>Inglês</option>
                                        <option value="ar" <?=$json['app_language']=='ar'?'selected':'' ?>>Àrabe</option>
										<option value="bn" <?=$json['app_language']=='bn'?'selected':'' ?>>Bengali</option>
										<option value="zh" <?=$json['app_language']=='zh'?'selected':'' ?>>Chinese</option>
										<option value="fr" <?=$json['app_language']=='fr'?'selected':'' ?>>Francês</option>
                                        <option value="hi"<?=$json['app_language']=='hi'?'selected':'' ?>>Hindi</option>
                                        <option value="it" <?=$json['app_language']=='it'?'selected':'' ?>>Italiano</option>
										<option value="ml" <?=$json['app_language']=='ml'?'selected':'' ?>>Malaiala</option>
										<option value="pt" <?=$json['app_language']=='pt'?'selected':'' ?>>Português</option>
										<option value="es" <?=$json['app_language']=='es'?'selected':'' ?>>Espanhol</option>
                                        <option value="ru" <?=$json['app_language']=='ru'?'selected':'' ?>>Russo</option>
										<option value="sv" <?=$json['app_language']=='sv'?'selected':'' ?>>Espanhol</option>
                                    </select>
									</div>
                                <div class="form-group">
                                    <div>
                                    </div>
                                    </div>
                            <form method="post">
							<div class="form-group ">
                                    <label class="control-label requiredField" for="language" >
                                        <strong> Escolha seu idioma</strong>
                                    </label>
                                    <select class="select form-control " id="select" name="language">
									    <option value="en"<?=$json['language']=='en'?'selected':'' ?>>Inglês</option>
                                        <option value="ar" <?=$json['language']=='ar'?'selected':'' ?>>Àrabe</option>
										<option value="bn" <?=$json['language']=='bn'?'selected':'' ?>>Bengali</option>
										<option value="zh" <?=$json['language']=='zh'?'selected':'' ?>>Chinese</option>
										<option value="fr" <?=$json['language']=='fr'?'selected':'' ?>>Francês</option>
                                        <option value="hi"<?=$json['language']=='hi'?'selected':'' ?>>Hindi</option>
                                        <option value="it" <?=$json['language']=='it'?'selected':'' ?>>Italiano</option>
										<option value="ml" <?=$json['language']=='ml'?'selected':'' ?>>Malaiala</option>
										<option value="pt" <?=$json['language']=='pt'?'selected':'' ?>>Português</option>
										<option value="es" <?=$json['language']=='es'?'selected':'' ?>>Espanhol</option>
                                        <option value="ru" <?=$json['language']=='ru'?'selected':'' ?>>Russo</option>
										<option value="sv" <?=$json['language']=='sv'?'selected':'' ?>>Espanhol</option>
                                    </select>
									</div>
                                </form>
                                <div class="form-group">
                                    <div>
                                        <button class="btn btn-primary" name="submit" type="submit">
                                            <i class="fa fa-check"></i> Enviar
                                        </button>
                            
                        </div>
                                          </div>
                                </form>
                                    </div>
                                     </div>
    </div>
                                   
</div> 
                                    
                                    
<script> 
$(document).ready(function () {
    $("#flash-msg").delay(3000).fadeOut("slow");
});
  </script>

<?php include ('includes/footer.php');?>
