/Quản lý website đọc truyện online PHP/soo/includes/editvote.php

https://gitlab.com/phamngsinh/baitaplon_sinhvien · PHP · 109 lines · 96 code · 2 blank · 11 comment · 25 complexity · ce943ef2ab7e5efc539306389db7fde9 MD5 · raw file

  1. <?php
  2. /*
  3. WMR: R118530587041
  4. ICQ: 365848916
  5. Автор: VladiSs
  6. Сайт: http://wapnex.ru
  7. */
  8. defined('_IN_JOHNCMS') or die('Error: restricted access');
  9. $us = mysql_fetch_array(mysql_query("SELECT * FROM `soo_users` where `website` = '$website' AND `sid` = ' " . $sid . " ' AND `user_id`=' " . $user_id . " ' "));
  10. if ($us['rights'] >= 8) {
  11. $topic_vote = mysql_result(mysql_query("SELECT COUNT(*) FROM `soo_forum_vote` where `website` = '$website' AND `type`='1' AND `topic`='$id'"), 0);
  12. require('../incfiles/head.php');
  13. if ($topic_vote == 0) {
  14. echo functions::display_error($lng['error_wrong_data']);
  15. require('../incfiles/end.php');
  16. exit;
  17. }
  18. if (isset($_GET['delvote']) && !empty($_GET['vote'])) {
  19. $vote = abs(intval($_GET['vote']));
  20. $totalvote = mysql_result(mysql_query("SELECT COUNT(*) FROM `soo_forum_vote` where `website` = '$website' AND `type` = '2' AND `id` = '$vote' AND `topic` = '$id'"), 0);
  21. $countvote = mysql_result(mysql_query("SELECT COUNT(*) FROM `soo_forum_vote` where `website` = '$website' AND `type` = '2' AND `topic` = '$id'"), 0);
  22. if ($countvote <= 2)
  23. header('location: ../soo/?mod=forum&act=editvote&id=' . $id . '');
  24. if ($totalvote != 0) {
  25. if (isset($_GET['yes'])) {
  26. mysql_query("DELETE FROM `soo_forum_vote` where `website` = '$website' AND `id` = '$vote'");
  27. $countus = mysql_result(mysql_query("SELECT COUNT(*) FROM `soo_forum_vote_users` where `website` = '$website' AND `vote` = '$vote' AND `topic` = '$id'"), 0);
  28. $topic_vote = mysql_fetch_array(mysql_query("SELECT `count` FROM `soo_forum_vote` where `website` = '$website' AND `type` = '1' AND `topic` = '$id' LIMIT 1"));
  29. $totalcount = $topic_vote['count'] - $countus;
  30. mysql_query("UPDATE `soo_forum_vote` SET `count` = '$totalcount' where `website` = '$website' AND `type` = '1' AND `topic` = '$id'");
  31. mysql_query("DELETE FROM `soo_forum_vote_users` where `website` = '$website' AND `vote` = '$vote'");
  32. header('location: ?mod=forum&act=editvote&sid='. $sid .'&id=' . $id . '');
  33. } else {
  34. echo '<div class="rmenu"><p>' . $lng_forum['voting_variant_warning'] . '<br />' .
  35. '<a href="../soo/?mod=forum&amp;act=editvote&amp&sid='. $sid .'&amp;id=' . $id . '&amp;vote=' . $vote . '&amp;delvote&amp;yes">' . $lng['delete'] . '</a><br />' .
  36. '<a href="' . htmlspecialchars(getenv("HTTP_REFERER")) . '">' . $lng['cancel'] . '</a></p></div>';
  37. }
  38. } else {
  39. header('location: ../soo/?mod=forum&act=editvote&id=' . $id . '');
  40. }
  41. } else if (isset($_POST['submit'])) {
  42. $vote_name = mb_substr(trim($_POST['name_vote']), 0, 50);
  43. if (!empty($vote_name))
  44. mysql_query("UPDATE `soo_forum_vote` SET `name` = '" . mysql_real_escape_string($vote_name) . "' where `website` = '$website' AND `topic` = '$id' AND `type` = '1'");
  45. $vote_result = mysql_query("SELECT `id` FROM `soo_forum_vote` where `website` = '$website' AND `type`='2' AND `topic`='" . $id . "'");
  46. while ($vote = mysql_fetch_array($vote_result)) {
  47. if (!empty($_POST[$vote['id'] . 'vote'])) {
  48. $text = mb_substr(trim($_POST[$vote['id'] . 'vote']), 0, 30);
  49. mysql_query("UPDATE `soo_forum_vote` SET `name` = '" . mysql_real_escape_string($text) . "' where `website` = '$website' AND `id` = '" . $vote['id'] . "'");
  50. }
  51. }
  52. $countvote = mysql_result(mysql_query("SELECT COUNT(*) FROM `soo_forum_vote` where `website` = '$website' AND `type`='2' AND `topic`='" . $id . "'"), 0);
  53. for ($vote = $countvote; $vote < 20; $vote++) {
  54. if (!empty($_POST[$vote])) {
  55. $text = mb_substr(trim($_POST[$vote]), 0, 30);
  56. mysql_query("INSERT INTO `soo_forum_vote` SET `name` = '" . mysql_real_escape_string($text) . "', `type` = '2', `topic` = '$id', `website` = '$website'");
  57. }
  58. }
  59. echo '<div class="gmenu"><p>' . $lng_forum['voting_changed'] . '<br /><a href="../soo/?mod=forum&amp;&sid='. $sid .'&amp;id=' . $id . '">' . $lng['continue'] . '</a></p></div>';
  60. } else {
  61. /*
  62. -----------------------------------------------------------------
  63. Форма редактирования опроса
  64. -----------------------------------------------------------------
  65. */
  66. $countvote = mysql_result(mysql_query("SELECT COUNT(*) FROM `soo_forum_vote` where `website` = '$website' AND `type` = '2' AND `topic` = '$id'"), 0);
  67. $topic_vote = mysql_fetch_array(mysql_query("SELECT `name` FROM `soo_forum_vote` where `website` = '$website' AND `type` = '1' AND `topic` = '$id' LIMIT 1"));
  68. echo '<div class="phdr"><a href="../soo/?mod=forum&amp;&sid='. $sid .'&amp;id=' . $id . '"><b>' . $lng['forum'] . '</b></a> | ' . $lng_forum['edit_vote'] . '</div>' .
  69. '<form action="../soo/?mod=forum&amp;act=editvote&amp;&sid='. $sid .'&amp;id=' . $id . '" method="post">' .
  70. '<div class="gmenu"><p>' .
  71. '<b>' . $lng_forum['voting'] . ':</b><br/>' .
  72. '<input type="text" size="20" maxlength="150" name="name_vote" value="' . htmlentities($topic_vote['name'], ENT_QUOTES, 'UTF-8') . '"/>' .
  73. '</p></div>' .
  74. '<div class="menu"><p>';
  75. $vote_result = mysql_query("SELECT `id`, `name` FROM `soo_forum_vote` where `website` = '$website' AND `type` = '2' AND `topic` = '$id'");
  76. while ($vote = mysql_fetch_array($vote_result)) {
  77. echo $lng_forum['answer'] . ' ' . ($i + 1) . ' (max. 50): <br/>' .
  78. '<input type="text" name="' . $vote['id'] . 'vote" value="' . htmlentities($vote['name'], ENT_QUOTES, 'UTF-8') . '"/>';
  79. if ($countvote > 2)
  80. echo '&nbsp;<a href="../soo/?mod=forum&amp;act=editvote&amp;&sid='. $sid .'&amp;id=' . $id . '&amp;vote=' . $vote['id'] . '&amp;delvote">[x]</a>';
  81. echo '<br/>';
  82. ++$i;
  83. }
  84. if ($countvote < 20) {
  85. if (isset($_POST['plus']))
  86. ++$_POST['count_vote'];
  87. elseif (isset($_POST['minus']))
  88. --$_POST['count_vote'];
  89. if (empty($_POST['count_vote']))
  90. $_POST['count_vote'] = $countvote;
  91. elseif ($_POST['count_vote'] > 20)
  92. $_POST['count_vote'] = 20;
  93. for ($vote = $i; $vote < $_POST['count_vote']; $vote++) {
  94. echo 'Ответ ' . ($vote + 1) . '(max. 50): <br/><input type="text" name="' . $vote . '" value="' . functions::checkout($_POST[$vote]) . '"/><br/>';
  95. }
  96. echo '<input type="hidden" name="count_vote" value="' . abs(intval($_POST['count_vote'])) . '"/>' . ($_POST['count_vote'] < 20 ? '<input type="submit" name="plus" value="' . $lng['add'] . '"/>' : '')
  97. . ($_POST['count_vote'] - $countvote ? '<input type="submit" name="minus" value="' . $lng_forum['delete_last'] . '"/>' : '');
  98. }
  99. echo '</p></div><div class="gmenu">' .
  100. '<p><input type="submit" name="submit" value="' . $lng['save'] . '"/></p>' .
  101. '</div></form>' .
  102. '<div class="phdr"><a href="../soo/?mod=forum&amp;&sid='. $sid .'&amp;id=' . $id . '">' . $lng['cancel'] . '</a></div>';
  103. }
  104. }
  105. require('../incfiles/end.php');
  106. break;
  107. ?>