simpleWordsCloud/create.php

59 lines
1.7 KiB
PHP

<?php
include('init.php');
include('templates/header.php');
if (empty($_POST)) {
?>
<div id="cloud_create">
<form method="post" action="create.php">
<div class="cloud_create_element">
<label id="ftext_l" for="ftext"><?php echo L::cloud_description ?></label>
<textarea id="ftext" name="ftext" rows="3" cols="50" placeholder="<?php echo L::cloud_description_message ?>"></textarea>
</div>
<div class="cloud_create_element">
<label for="fduration"><span title="<?php echo L::cloud_duration_tooltip ?>"><?php echo L::cloud_duration ?></span></label>
<select id="fduration" name="fduration">
<?php
foreach (DataBase::OPTIONS_DURATION as $name => $duration) {
echo sprintf('<option value="%s">%s</option>', $name, constant('L::duration_' . $name));
}
?>
</select>
</div>
<div class="cloud_create_element">
<label for="fsize"><?php echo L::cloud_size ?></label>
<input type="number" id="fsize" name="fsize" min="1" max="9" value=<?php echo DataBase::DEFAULT_SIZE ?>>
</div>
<input type="submit" id="cloud_create_submit" value="<?php echo L::create_button ?>">
</form>
</div>
<?php
} else {
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']) && key_exists($_POST['fduration'], DataBase::OPTIONS_DURATION)) {
$duration = $_POST['fduration'];
} else {
$duration = DataBase::DEFAULT_DURATION;
}
if ($cloud = $db->createCloud($text, $size, $duration)) {
$viewUrl = 'result.php?id=' . $cloud['code'];
header('Location: ' . $viewUrl);
die();
} else {
?>
<h2><?php echo L::create_errorCode ?></h2>
<?php
}
}
include('templates/footer.php');