Файл: modules/forum/action/create_vote.php
Строк: 200
<?php
/* DCMS Special
* Дата последнего редактирования 19.12.2015
* Модифицировал densnet
* Автор yadalay
*/
if ($vars == 0) {
mysql_query('INSERT INTO `forum_votes` SET `id_theme` = ' . $theme->id . ', `id_user` = ' . $user['id'] . ', `name` = " ", `time` = "0", `time_end` = "0"');
$insert = mysql_insert_id();
mysql_query('INSERT INTO `forum_votes_var` SET `id_theme` = ' . $theme->id . ', `id_vote` = ' . $insert . ', `variant` = ""');
mysql_query('INSERT INTO `forum_votes_var` SET `id_theme` = ' . $theme->id . ', `id_vote` = ' . $insert . ', `variant` = ""');
header('Location: ' . DIR_FORUM . $forum->id . '/' . $razdel->id . '/' . $theme->id . '/create_vote.html');
exit;
}
if (isset($_POST['create'])) {
$name = mysql_real_escape_string(trim($_POST['name']));
if ($_POST['time_end'] == 1 || ($_POST['time_end'] != 1 && $_POST['time_end'] != 2 && $_POST['time_end'] != 3 && $_POST['time_end'] != 4 && $_POST['time_end'] != 5 && $_POST['time_end'] != 6)) {
$time_end = 0;
} elseif ($_POST['time_end'] == 2) {
$time_end = time() + 60 * 60 * 24;
} elseif ($_POST['time_end'] == 3) {
$time_end = time() + 60 * 60 * 72;
} elseif ($_POST['time_end'] == 4) {
$time_end = time() + 60 * 60 * 24 * 7;
} elseif ($_POST['time_end'] == 5) {
$time_end = time() + 60 * 60 * 24 * 30;
} elseif ($_POST['time_end'] == 6) {
$time_end = time() + 60 * 60 * 24 * 90;
}
if (mb_strlen($name) < 5) {
echo "<div class='alert alert-danger'>Слишком короткое содержание опроса.</div>";
} else {
$var = $_POST['var'];
$count_var = count($var);
for ($i = 0; $i < $count_var; $i++) {
unset($_SESSION['var'][$i]);
$var[$i] = mysql_real_escape_string(trim($var[$i]));
mysql_query('INSERT INTO `forum_votes_var` SET `id_theme` = ' . $theme->id . ', `variant` = "' . mysql_real_escape_string($var[$i]) . '", `id_vote` = ' . $vote->id);
}
unset($_SESSION['name']);
unset($_SESSION['time_end']);
$_SESSION['success'] = '<div class="alert alert-success">Опрос успешно прикреплён к теме.</div>';
mysql_query('UPDATE `forum_votes` SET `name` = "' . $name . '", `time` = ' . $time . ', `time_end` = ' . $time_end . ' WHERE `id_theme` = ' . $theme->id);
mysql_query('DELETE FROM `forum_votes_var` WHERE `id_theme` = ' . $theme->id . ' AND `variant` = ""');
header('Location: ' . DIR_FORUM . $forum->id . '/' . $razdel->id . '/' . $theme->id . '.html');
exit;
}
} elseif (isset($_POST['add_var']) && $vars < 8) {
$_SESSION['name'] = $_POST['name'];
$_SESSION['time_end'] = $_POST['time_end'];
$var = $_POST['var'];
$count_var = count($var);
for ($i = 0; $i < $count_var; $i++) {
$_SESSION['var'][$i] = mysql_real_escape_string(trim($var[$i]));
}
mysql_query('INSERT INTO `forum_votes_var` SET `id_theme` = ' . $theme->id . ', `id_vote` = ' . $vote->id . ', `variant` = ""');
header('Location: ' . DIR_FORUM . $forum->id . '/' . $razdel->id . '/' . $theme->id . '/create_vote.html');
exit;
} elseif (isset($_POST['delete_var']) && $vars > 2) {
$_SESSION['name'] = $_POST['name'];
$_SESSION['time_end'] = $_POST['time_end'];
$var = $_POST['var'];
$count_var = count($var) - 1;
unset($_SESSION['var'][$count_var]);
mysql_query('DELETE FROM `forum_votes_var` WHERE `id_theme` ORDER by `id` DESC LIMIT 1');
header('Location: ' . DIR_FORUM . $forum->id . '/' . $razdel->id . '/' . $theme->id . '/create_vote.html');
exit;
} elseif (isset($_POST['cancel'])) {
$_SESSION['success'] = '<div class="alert alert-success">Опрос успешно отменён.</div>';
$var = $_POST['var'];
$count_var = count($var);
for ($i = 0; $i < $count_var; $i++) {
unset($_SESSION['var'][$i]);
}
unset($_SESSION['name']);
unset($_SESSION['time_end']);
mysql_query('DELETE FROM `forum_votes` WHERE `id_theme` = ' . $theme->id);
mysql_query('DELETE FROM `forum_votes_var` WHERE `id_theme` = ' . $theme->id);
header('Location: ' . DIR_FORUM . $forum->id . '/' . $razdel->id . '/' . $theme->id . '.html');
exit;
}
#Навигация
echo "<nav class='navbar navbar-light' style='background-color: #607D8B; color: #fff;'>";
echo "<ul class='nav navbar-nav'>";
echo "<li class='nav-item' style='margin-left: 1px;'><a class='nav-link' href='/'><i class='material-icons'>home</i></a></li>";
echo "<li class='nav-item' style='margin-left: 1px;'><a class='nav-link'><i class='material-icons'>keyboard_arrow_right</i></a></li>";
echo "<li class='nav-item' style='margin-left: 1px;'><a class='nav-link' href='" . DIR_FORUM . "'>Форум</a></li>";
echo "<li class='nav-item' style='margin-left: 1px;'><a class='nav-link'><i class='material-icons'>keyboard_arrow_right</i></a></li>";
echo "<li class='nav-item' style='margin-left: 1px;'><a class='nav-link' href='" . DIR_FORUM . "$forum->id/'>" . toOutput($forum->name, 1, 1, 0, 0, 0) . "</a></li>";
echo "<li class='nav-item' style='margin-left: 1px;'><a class='nav-link'><i class='material-icons'>keyboard_arrow_right</i></a></li>";
echo "<li class='nav-item' style='margin-left: 1px;'><a class='nav-link' href='" . DIR_FORUM . "$forum->id/$razdel->id/'>" . toOutput($razdel->name, 1, 1, 0, 0, 0) . "</a></li>";
echo "<li class='nav-item' style='margin-left: 1px;'><a class='nav-link'><i class='material-icons'>keyboard_arrow_right</i></a></li>";
echo "<li class='nav-item' style='margin-left: 1px;'><a class='nav-link' href='" . DIR_FORUM . "$forum->id/$razdel->id/$theme->id.html'>" . toOutput($theme->name, 1, 0, 0, 0, 0) . "</a></li>";
echo "<li class='nav-item' style='margin-left: 1px;'><a class='nav-link'><i class='material-icons'>keyboard_arrow_right</i></a></li>";
echo "<li class='nav-item' style='margin-left: 1px;'><a class='nav-link'>Создание опроса</a></li>";
echo "</ul>";
echo "</nav>";
echo "<form class='list-group-item' action='" . DIR_FORUM . "$forum->id/$razdel->id/$theme->id/create_vote.html' method='post'>";
echo "<div class='row'>";
echo "<div class='input-field col s12'>";
echo "<textarea name='name' id='name' class='materialize-textarea'>" . ((isset($_SESSION['name'])) ? toOutput($_SESSION['name']) : NULL) . "</textarea>";
echo "<label for='name'>Содержание опроса</label>";
echo "</div>";
echo "</div>";
echo "Варианты ответов:<br />";
for ($i = 0; $i < $vars; $i++) {
echo "<div class='row'>";
echo "<div class='input-field col s6'>";
echo "<input name='var[]' type='text' value='" . ((isset($_SESSION['var'][$i])) ? toOutput($_SESSION['var'][$i]) : NULL) . "' class='validate'>";
echo "</div>";
echo "</div>";
}
echo "<button class='btn waves-effect waves-light' type='submit' name='add_var' " . (($vars > 7) ? 'disabled="disabled"' : NULL) . ">Ещё вариант</button> ";
echo "<button class='btn waves-effect waves-light' type='submit' name='delete_var' " . (($vars < 3) ? 'disabled="disabled"' : NULL) . ">Убрать вариант</button><br />";
echo "Дата окончания через:<br />";
echo "<select name='time_end' class='browser-default' style='width: 50%'>";
?>
<option value="1" <?= (isset($_SESSION['time_end']) && $_SESSION['time_end'] == 1) ? 'selected="selected"' : NULL ?>>Бессрочно</option>
<option value="2" <?= (isset($_SESSION['time_end']) && $_SESSION['time_end'] == 2) ? 'selected="selected"' : NULL ?>>1 День</option>
<option value="3" <?= (isset($_SESSION['time_end']) && $_SESSION['time_end'] == 3) ? 'selected="selected"' : NULL ?>>3 Дня</option>
<option value="4" <?= (isset($_SESSION['time_end']) && $_SESSION['time_end'] == 4) ? 'selected="selected"' : NULL ?>>1 Неделю</option>
<option value="5" <?= (isset($_SESSION['time_end']) && $_SESSION['time_end'] == 5) ? 'selected="selected"' : NULL ?>>1 месяц</option>
<option value="6" <?= (isset($_SESSION['time_end']) && $_SESSION['time_end'] == 6) ? 'selected="selected"' : NULL ?>>3 месяца</option>
<?php
echo "</select>";
echo "<div class='hr'></div>";
echo "<button name='create' class='btn waves-effect waves-light'>Создать опрос</button> ";
echo "<button name='create' class='btn waves-effect waves-light btn-secondary'>Отменить</button>";
echo "</form>";
require_once H . 'sys/inc/tfoot.php';
exit;