First working version
This commit is contained in:
parent
8a6973fcb6
commit
baa592b81f
8 changed files with 192 additions and 51 deletions
44
create.php
44
create.php
|
@ -2,6 +2,29 @@
|
|||
|
||||
include('templates/header.php');
|
||||
include('db.php');
|
||||
|
||||
if (empty($_POST)) {
|
||||
?>
|
||||
<div id="cloud_create">
|
||||
<form method="post" action="create.php">
|
||||
<label for="ftext">Description du nuage</label>
|
||||
<input type="text" id="ftext" name="ftext" placeholder="Votre texte ici">
|
||||
<label for="fduration">Durée de vie du nuage</label>
|
||||
<select id="fduration" name="fduration">
|
||||
<?php
|
||||
foreach (DataBase::OPTIONS_DURATION as $name => $duration) {
|
||||
echo sprintf('<option valu="%s">%s</option>', $name, $name);
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
<label for="fsize">Nombre de mots par entrée (entre 1 et 9)</label>
|
||||
<input type="number" id="fsize" name="fsize" min="1" max="9">
|
||||
<input type="submit" value="Créer">
|
||||
</form>
|
||||
</div>
|
||||
<?php
|
||||
} else {
|
||||
|
||||
$db = new DataBase();
|
||||
if (!$db->isInit()) {
|
||||
echo 'Error db init';
|
||||
|
@ -12,9 +35,25 @@ $db->cleanCloud();
|
|||
|
||||
$length = 6;
|
||||
$token = bin2hex(random_bytes($length));
|
||||
|
||||
while (!$db->createCloud($token)) {
|
||||
if (isset($_POST['fsize']) && is_numeric($_POST['fsize'])) {
|
||||
$size = $_POST['fsize'];
|
||||
} else {
|
||||
$size = 3;
|
||||
}
|
||||
if (isset($_POST['ftext'])) {
|
||||
$text = $_POST['ftext'];
|
||||
} else {
|
||||
$text = '';
|
||||
}
|
||||
if (isset($_POST['fduration']) && in_array($_POST['fduration'], DataBase::OPTIONS_DURATION)) {
|
||||
$duration = $_POST['fduration'];
|
||||
} else {
|
||||
$duration = DataBase::DEFAULT_DURATION;
|
||||
}
|
||||
$cpt = 0;
|
||||
while (!$db->createCloud($token, $text, $size, $duration) && $cpt < 10) {
|
||||
$token = bin2hex(random_bytes($length));
|
||||
$cpt++;
|
||||
}
|
||||
?>
|
||||
|
||||
|
@ -33,4 +72,5 @@ while (!$db->createCloud($token)) {
|
|||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
include('templates/footer.php');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue