172 lines
4.2 KiB
PHP
172 lines
4.2 KiB
PHP
<!DOCTYPE html>
|
|
<html>
|
|
<?php
|
|
// Gestion du multilingue
|
|
$langa = explode(',',$_SERVER['HTTP_ACCEPT_LANGUAGE']);
|
|
$langa = strtolower(substr(chop($langa[0]),0,2));
|
|
|
|
$_SESSION['lang'] = $langa;
|
|
|
|
if ($_SESSION['lang']=='en')
|
|
include('lang/en.php');
|
|
else if ($_SESSION['lang']=='fr')
|
|
include('./lang/fr.php');
|
|
else include('./lang/en.php');
|
|
|
|
?>
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf8" />
|
|
<meta name="description" content="Generate random name for khanat people">
|
|
<meta name="author" content="Khaganat">
|
|
<link href="./css/form.css" type="text/css" rel="stylesheet">
|
|
<link href="./css/main.css" type="text/css" rel="stylesheet">
|
|
|
|
<title><?php echo txt_title1;?></title>
|
|
|
|
|
|
|
|
</head>
|
|
|
|
|
|
|
|
<body>
|
|
<?php // Barre générale Khaganat
|
|
include_once("/var/www/khanav/khnav.php");
|
|
// Fin Barre générale Khaganat
|
|
?>
|
|
|
|
|
|
<div class="gen">
|
|
<h1><?php echo txt_title1;?></h1>
|
|
<div class="explain"><?php echo txt_explain;?></div>
|
|
<form method="get">
|
|
<div class=form1>
|
|
<!-- Region -->
|
|
<div class="entry"><?php echo txt_region;?>
|
|
<select class="select" name="regions">
|
|
<?php
|
|
foreach(glob("./name/region_*.csv") as $filename) {
|
|
$opt = substr($filename, 14, strlen($filename)-18);
|
|
echo '<option value="'.$opt.'">'.$opt.'</option>';
|
|
}
|
|
?>
|
|
</select>
|
|
</div>
|
|
<!-- Number syllabe -->
|
|
<div class="entry">
|
|
<?php echo txt_number_syllabe;?>
|
|
<input class="number" type="number" name="nb_syllabes" value="<?php echo (isset($_GET["nb_syllabes"])?$_GET["nb_syllabes"]:1) ?>">
|
|
</div>
|
|
<!-- Number name -->
|
|
<div class="entry">
|
|
<?php echo txt_number_name;?>
|
|
<input class="number" type="number" name="count" value="<?php echo (isset($_GET["count"])?$_GET["count"]:1) ?>">
|
|
</div>
|
|
|
|
<input class="submit" type="submit" value="<?php echo txt_generate; ?>">
|
|
</div>
|
|
|
|
<!-- Table with result -->
|
|
<div>
|
|
|
|
<?php
|
|
|
|
if (isset($_GET["regions"]) && isset($_GET["nb_syllabes"]) && isset($_GET["count"])) {
|
|
creation_requested();
|
|
}
|
|
|
|
function create_name($wanted_length, $dict) {
|
|
$name_length = 1;
|
|
$name = "";
|
|
$tanru = "";
|
|
$description = "";
|
|
while($name_length <= $wanted_length) {
|
|
$random = rand(0, count($dict)-1);
|
|
$name .= $dict[$random][0];
|
|
$tanru .= $dict[$random][1] . ($name_length != $wanted_length?" / ":"");
|
|
$description .= $dict[$random][2] . ($name_length != $wanted_length?" / ":"");
|
|
$name_length++;
|
|
}
|
|
return array($name, $tanru, $description);
|
|
}
|
|
|
|
function creation_requested() {
|
|
$region = $_GET["regions"];
|
|
$nb_syllabes = $_GET["nb_syllabes"];
|
|
$count = $_GET["count"];
|
|
|
|
$region_file = "./name/region_" . $region . ".csv";
|
|
|
|
$sem_spaces = array();
|
|
|
|
if (!file_exists($region_file)) {
|
|
exit("<h1>Error: region file not found.</h1>");
|
|
}
|
|
|
|
$file = fopen($region_file, "r");
|
|
|
|
if (!feof($file)) {
|
|
fgets($file);
|
|
}
|
|
|
|
while(! feof($file)) {
|
|
$csv = fgetcsv($file);
|
|
if ($csv) {
|
|
array_push($sem_spaces, $csv);
|
|
}
|
|
}
|
|
|
|
fclose($file);
|
|
|
|
$dict = array();
|
|
|
|
foreach($sem_spaces as $line) {
|
|
if (!file_exists("./name/sem_" . $line[0] . ".csv")) {
|
|
exit("<h1>Error: semantics file " . $line[0] . " not found.</h1>");
|
|
}
|
|
$file_sem = fopen("./name/sem_" . $line[0] . ".csv", "r");
|
|
while(!feof($file_sem)) {
|
|
$sem = fgetcsv($file_sem);
|
|
if ($sem) {
|
|
for ($i = 0; $i < $line[1]; $i++) {
|
|
array_push($dict, $sem);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if (count($dict) == 0) {
|
|
exit("<h1>Error: no name parts found.</h1>");
|
|
}
|
|
|
|
$result = array();
|
|
|
|
for ($i = 0; $i < $count; $i++) {
|
|
array_push($result, create_name($nb_syllabes, $dict));
|
|
}
|
|
|
|
$out .= "<table>";
|
|
$out .= "<tr>";
|
|
$out .= "<th>" . txt_name . "</th>" . "<th>" . txt_gismu . "</th>" . "<th>" . txt_translate . "</th>" ;
|
|
$out .= "</tr>";
|
|
foreach($result as $key => $element){
|
|
$out .= "<tr>";
|
|
foreach($element as $subkey => $subelement){
|
|
$out .= "<td>$subelement</td>";
|
|
}
|
|
$out .= "</tr>";
|
|
}
|
|
$out .= "</table>";
|
|
|
|
echo $out;
|
|
}
|
|
?>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
<?php // Footer général Khaganat
|
|
include_once("/var/www/khanav/khfooter.php");
|
|
// Fin Footer général Khaganat
|
|
?>
|
|
</body>
|
|
</html>
|