From 6c85e96e1c39ae0663b84d6938183009178d79f1 Mon Sep 17 00:00:00 2001 From: nanosimbiot Date: Thu, 30 Jan 2014 17:02:21 +0000 Subject: [PATCH] r575 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Новый опросник, начало обновления структуры лс и постов. Запрос для обновления: sql CREATE TABLE IF NOT EXISTS `bb_poll_users` ( `topic_id` int(10) unsigned NOT NULL, `user_id` int(11) NOT NULL, `vote_ip` varchar(32) NOT NULL, `vote_dt` int(11) NOT NULL DEFAULT '0', PRIMARY KEY (`topic_id`,`user_id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; CREATE TABLE IF NOT EXISTS `bb_poll_votes` ( `topic_id` int(10) unsigned NOT NULL, `vote_id` tinyint(4) unsigned NOT NULL, `vote_text` varchar(255) NOT NULL, `vote_result` mediumint(8) unsigned NOT NULL, PRIMARY KEY (`topic_id`,`vote_id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; git-svn-id: https://torrentpier2.googlecode.com/svn/trunk@575 a8ac35ab-4ca4-ca47-4c2d-a49a94f06293 --- install/sql/mysql.sql | 79 +++---- upgrade/r575-poll_upgrade.php | 59 +++++ upload/attach_mod/posting_attachments.php | 4 +- upload/config.php | 3 +- upload/includes/functions.php | 102 +++++++++ upload/includes/functions_admin.php | 38 +-- upload/includes/functions_post.php | 150 +----------- upload/includes/init_bb.php | 10 +- upload/language/lang_english/lang_main.php | 12 +- upload/language/lang_russian/lang_main.php | 12 +- upload/poll.php | 241 ++++++++++++++++++++ upload/posting.php | 235 ++----------------- upload/templates/default/viewtopic.tpl | 60 ++++- upload/templates/default/viewtopic_poll.tpl | 174 +++++++++++--- upload/viewtopic.php | 167 +++----------- 15 files changed, 720 insertions(+), 626 deletions(-) create mode 100644 upgrade/r575-poll_upgrade.php create mode 100644 upload/poll.php diff --git a/install/sql/mysql.sql b/install/sql/mysql.sql index 26666c4dd..f33f8e086 100644 --- a/install/sql/mysql.sql +++ b/install/sql/mysql.sql @@ -43,6 +43,8 @@ DROP TABLE IF EXISTS `bb_extension_groups`; DROP TABLE IF EXISTS `bb_forums`; DROP TABLE IF EXISTS `bb_groups`; DROP TABLE IF EXISTS `bb_log`; +DROP TABLE IF EXISTS `bb_poll_users`; +DROP TABLE IF EXISTS `bb_poll_votes`; DROP TABLE IF EXISTS `bb_posts`; DROP TABLE IF EXISTS `bb_posts_html`; DROP TABLE IF EXISTS `bb_posts_search`; @@ -65,9 +67,6 @@ DROP TABLE IF EXISTS `bb_topic_templates`; DROP TABLE IF EXISTS `bb_topic_tpl`; DROP TABLE IF EXISTS `bb_users`; DROP TABLE IF EXISTS `bb_user_group`; -DROP TABLE IF EXISTS `bb_vote_desc`; -DROP TABLE IF EXISTS `bb_vote_results`; -DROP TABLE IF EXISTS `bb_vote_voters`; DROP TABLE IF EXISTS `bb_words`; DROP TABLE IF EXISTS `buf_last_seeder`; DROP TABLE IF EXISTS `buf_topic_view`; @@ -856,6 +855,34 @@ CREATE TABLE IF NOT EXISTS `bb_log` ( -- -------------------------------------------------------- +-- +-- Структура таблицы `bb_poll_users` +-- + +CREATE TABLE IF NOT EXISTS `bb_poll_users` ( + `topic_id` int(10) unsigned NOT NULL, + `user_id` int(11) NOT NULL, + `vote_ip` varchar(32) NOT NULL, + `vote_dt` int(11) NOT NULL DEFAULT '0', + PRIMARY KEY (`topic_id`,`user_id`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8; + +-- -------------------------------------------------------- + +-- +-- Структура таблицы `bb_poll_votes` +-- + +CREATE TABLE IF NOT EXISTS `bb_poll_votes` ( + `topic_id` int(10) unsigned NOT NULL, + `vote_id` tinyint(4) unsigned NOT NULL, + `vote_text` varchar(255) NOT NULL, + `vote_result` mediumint(8) unsigned NOT NULL, + PRIMARY KEY (`topic_id`,`vote_id`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8; + +-- -------------------------------------------------------- + -- -- Структура таблицы `bb_posts` -- @@ -1415,52 +1442,6 @@ CREATE TABLE IF NOT EXISTS `bb_user_group` ( -- -------------------------------------------------------- --- --- Структура таблицы `bb_vote_desc` --- - -CREATE TABLE IF NOT EXISTS `bb_vote_desc` ( - `vote_id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT, - `topic_id` mediumint(8) unsigned NOT NULL DEFAULT '0', - `vote_text` text NOT NULL, - `vote_start` int(11) NOT NULL DEFAULT '0', - `vote_length` int(11) NOT NULL DEFAULT '0', - PRIMARY KEY (`vote_id`), - KEY `topic_id` (`topic_id`) -) ENGINE=MyISAM DEFAULT CHARSET=utf8; - --- -------------------------------------------------------- - --- --- Структура таблицы `bb_vote_results` --- - -CREATE TABLE IF NOT EXISTS `bb_vote_results` ( - `vote_id` mediumint(8) unsigned NOT NULL DEFAULT '0', - `vote_option_id` tinyint(4) unsigned NOT NULL DEFAULT '0', - `vote_option_text` varchar(255) NOT NULL DEFAULT '', - `vote_result` int(11) NOT NULL DEFAULT '0', - KEY `vote_option_id` (`vote_option_id`), - KEY `vote_id` (`vote_id`) -) ENGINE=MyISAM DEFAULT CHARSET=utf8; - --- -------------------------------------------------------- - --- --- Структура таблицы `bb_vote_voters` --- - -CREATE TABLE IF NOT EXISTS `bb_vote_voters` ( - `vote_id` mediumint(8) unsigned NOT NULL DEFAULT '0', - `vote_user_id` mediumint(8) NOT NULL DEFAULT '0', - `vote_user_ip` char(32) NOT NULL DEFAULT '', - KEY `vote_id` (`vote_id`), - KEY `vote_user_id` (`vote_user_id`), - KEY `vote_user_ip` (`vote_user_ip`) -) ENGINE=MyISAM DEFAULT CHARSET=utf8; - --- -------------------------------------------------------- - -- -- Структура таблицы `bb_words` -- diff --git a/upgrade/r575-poll_upgrade.php b/upgrade/r575-poll_upgrade.php new file mode 100644 index 000000000..d45797f6c --- /dev/null +++ b/upgrade/r575-poll_upgrade.php @@ -0,0 +1,59 @@ +session_start(); + +set_die_append_msg(); +if (!IS_SUPER_ADMIN) bb_die($lang['ONLY_FOR_SUPER_ADMIN']); + +$confirm = request_var('confirm', ''); + +if ($confirm) +{ + DB()->query(" + INSERT INTO bb_poll_votes + (topic_id, vote_id, vote_text, vote_result) + SELECT + topic_id, 0, vote_text, 0 + FROM bb_vote_desc; + "); + + DB()->query(" + INSERT INTO bb_poll_votes + (topic_id, vote_id, vote_text, vote_result) + SELECT + d.topic_id, r.vote_option_id, r.vote_option_text, r.vote_result + FROM bb_vote_desc d, bb_vote_results r + WHERE + d.vote_id = r.vote_id; + "); + + DB()->query(" + INSERT INTO bb_poll_users + (topic_id, user_id, vote_ip) + SELECT + d.topic_id, v.vote_user_id, v.vote_user_ip + FROM bb_vote_desc d, bb_vote_voters v + WHERE + d.vote_id = v.vote_id + AND v.vote_user_id > 0; + "); + + DB()->query("DROP TABLE IF EXISTS bb_vote_desc"); + DB()->query("DROP TABLE IF EXISTS bb_vote_results"); + DB()->query("DROP TABLE IF EXISTS bb_vote_voters"); + + bb_die('

База данных обновлена

'); +} +else +{ + $msg = '
'; + $msg .= '

!!! Перед тем как нажать на кнопку, сделайте бекап базы данных !!!


'; + $msg .= ''; + $msg .= '
'; + + bb_die($msg); +} \ No newline at end of file diff --git a/upload/attach_mod/posting_attachments.php b/upload/attach_mod/posting_attachments.php index ae76b419d..a427ddae1 100644 --- a/upload/attach_mod/posting_attachments.php +++ b/upload/attach_mod/posting_attachments.php @@ -257,7 +257,7 @@ class attach_parent if (!$submit && $mode == 'editpost' && $auth) { - if (!$refresh && !$preview && !$error && !isset($_POST['del_poll_option'])) + if (!$refresh && !$preview && !$error) { for ($i = 0; $i < sizeof($attachments); $i++) { @@ -276,7 +276,7 @@ class attach_parent $this->num_attachments = sizeof($this->attachment_list); - if ($submit && $mode != 'vote') + if ($submit) { if ($mode == 'newtopic' || $mode == 'reply' || $mode == 'editpost') { diff --git a/upload/config.php b/upload/config.php index f5eac042d..1762f9bbd 100644 --- a/upload/config.php +++ b/upload/config.php @@ -56,7 +56,7 @@ $domain_name = (!empty($_SERVER['SERVER_NAME'])) ? $_SERVER['SERVER_NAME'] : $do // Increase number of revision after update $bb_cfg['tp_version'] = '2.5 (unstable)'; $bb_cfg['tp_release_date'] = '30-01-2014'; -$bb_cfg['tp_release_state'] = 'R574'; +$bb_cfg['tp_release_state'] = 'R575'; // Database $charset = 'utf8'; @@ -518,6 +518,7 @@ $bb_cfg['use_word_censor'] = true; $bb_cfg['last_visit_date_format'] = 'd-M H:i'; $bb_cfg['last_post_date_format'] = 'd-M-y H:i'; +$bb_cfg['poll_max_days'] = 180; // сколько дней с момента создания темы опрос будет активным $bb_cfg['allow_change'] = array( 'language' => true, diff --git a/upload/includes/functions.php b/upload/includes/functions.php index f0d6f34a4..246a554cc 100644 --- a/upload/includes/functions.php +++ b/upload/includes/functions.php @@ -14,6 +14,9 @@ function get_tracks ($type) case 'forum': $c_name = COOKIE_FORUM; break; + case 'pm': + $c_name = COOKIE_PM; + break; default: trigger_error(__FUNCTION__ .": invalid type '$type'", E_USER_ERROR); } @@ -2395,6 +2398,45 @@ function build_topic_pagination ($url, $replies, $per_page) return $pg; } +// +// Poll +// +function get_poll_data_items_js ($topic_id) +{ + if (!$topic_id_csv = get_id_csv($topic_id)) + { + return is_array($topic_id) ? array() : false; + } + $items = array(); + + $sql = " + SELECT topic_id, vote_id, vote_text, vote_result + FROM ". BB_POLL_VOTES ." + WHERE topic_id IN($topic_id_csv) + ORDER BY topic_id, vote_id + "; + foreach (DB()->fetch_rowset($sql) as $row) + { + $opt_text_for_js = htmlCHR($row['vote_text']); + $opt_result_for_js = (int) $row['vote_result']; + + $items[$row['topic_id']][$row['vote_id']] = array($opt_text_for_js, $opt_result_for_js); + } + foreach ($items as $k => $v) + { + $items[$k] = php2js($v); + } + + return is_array($topic_id) ? $items : $items[$topic_id]; +} + +function poll_is_active ($t_data) +{ + global $bb_cfg; + return ($t_data['topic_vote'] == 1 && $t_data['topic_time'] > TIMENOW - $bb_cfg['poll_max_days']*86400); +} + + function print_confirmation ($tpl_vars) { global $template, $lang; @@ -2489,6 +2531,66 @@ function bb_json_decode ($data) return json_decode($data, true); } +/** + * -- from JsHttpRequest -- + * Convert a PHP scalar, array or hash to JS scalar/array/hash. This function is + * an analog of json_encode(), but it can work with a non-UTF8 input and does not + * analyze the passed data. Output format must be fully JSON compatible. + * + * @param mixed $a Any structure to convert to JS. + * @return string JavaScript equivalent structure. + */ +function php2js ($a = false) +{ + if (is_null($a)) return 'null'; + if ($a === false) return 'false'; + if ($a === true) return 'true'; + if (is_scalar($a)) + { + if (is_float($a)) + { + // Always use "." for floats. + $a = str_replace(",", ".", strval($a)); + } + // All scalars are converted to strings to avoid indeterminism. + // PHP's "1" and 1 are equal for all PHP operators, but + // JS's "1" and 1 are not. So if we pass "1" or 1 from the PHP backend, + // we should get the same result in the JS frontend (string). + // Character replacements for JSON. + static $jsonReplaces = array( + array("\\", "/", "\n", "\t", "\r", "\b", "\f", '"'), + array('\\\\', '\\/', '\\n', '\\t', '\\r', '\\b', '\\f', '\"'), + ); + return '"'. str_replace($jsonReplaces[0], $jsonReplaces[1], $a) .'"'; + } + $isList = true; + for ($i = 0, reset($a); $i < count($a); $i++, next($a)) + { + if (key($a) !== $i) + { + $isList = false; + break; + } + } + $result = array(); + if ($isList) + { + foreach ($a as $v) + { + $result[] = php2js($v); + } + return '[ '. join(', ', $result) .' ]'; + } + else + { + foreach ($a as $k => $v) + { + $result[] = php2js($k) .': '. php2js($v); + } + return '{ '. join(', ', $result) .' }'; + } +} + function clean_title ($str, $replace_underscore = false) { $str = ($replace_underscore) ? str_replace('_', ' ', $str) : $str; diff --git a/upload/includes/functions_admin.php b/upload/includes/functions_admin.php index a31ab2925..8eac1cf2d 100644 --- a/upload/includes/functions_admin.php +++ b/upload/includes/functions_admin.php @@ -289,11 +289,10 @@ function topic_delete ($mode_or_topic_id, $forum_id = null, $prune_time = 0, $pr // Delete votes DB()->query(" - DELETE vd, vr, vu + DELETE pv, pu FROM ". $tmp_delete_topics ." del - LEFT JOIN ". BB_VOTE_DESC ." vd USING(topic_id) - LEFT JOIN ". BB_VOTE_RESULTS ." vr USING(vote_id) - LEFT JOIN ". BB_VOTE_USERS ." vu USING(vote_id) + LEFT JOIN ". BB_POLL_VOTES ." pv USING(topic_id) + LEFT JOIN ". BB_POLL_USERS ." pu USING(vote_id) "); // Delete attachments (from disk) @@ -322,7 +321,7 @@ function topic_delete ($mode_or_topic_id, $forum_id = null, $prune_time = 0, $pr } } unset($row, $result); - + // Delete posts, posts_text, attachments (from DB) DB()->query(" DELETE p, pt, ps, a, d, ph @@ -708,26 +707,6 @@ function post_delete ($mode_or_post_id, $user_id = null, $exclude_first = true) return $deleted_posts_count; } -function poll_delete ($topic_id) -{ - if (!$topic_csv = get_id_csv($topic_id)) - { - return false; - } - - DB()->query(" - DELETE vd, vr, vu - FROM ". BB_VOTE_DESC ." vd - LEFT JOIN ". BB_VOTE_RESULTS ." vr USING(vote_id) - LEFT JOIN ". BB_VOTE_USERS ." vu USING(vote_id) - WHERE vd.topic_id IN($topic_csv) - "); - - DB()->query(" - UPDATE ". BB_TOPICS ." SET topic_vote = 0 WHERE topic_id IN($topic_csv) - "); -} - function user_delete ($user_id, $delete_posts = false) { global $bb_cfg, $log_action; @@ -791,12 +770,6 @@ function user_delete ($user_id, $delete_posts = false) WHERE topic_poster IN($user_csv) "); - DB()->query(" - UPDATE ". BB_VOTE_USERS ." SET - vote_user_id = ". DELETED ." - WHERE vote_user_id IN($user_csv) - "); - DB()->query(" UPDATE ". BB_BT_TORRENTS ." SET poster_id = ". DELETED ." @@ -814,9 +787,10 @@ function user_delete ($user_id, $delete_posts = false) "); DB()->query(" - DELETE u, ban, s, tw, asn + DELETE u, ban, pu, s, tw, asn FROM ". BB_USERS ." u LEFT JOIN ". BB_BANLIST ." ban ON(ban.ban_userid = u.user_id) + LEFT JOIN ". BB_POLL_USERS ." pu ON(pu.user_id = u.user_id) LEFT JOIN ". BB_SESSIONS ." s ON(s.session_user_id = u.user_id) LEFT JOIN ". BB_TOPICS_WATCH ." tw ON(tw.user_id = u.user_id) LEFT JOIN ". BB_AUTH_ACCESS_SNAP ." asn ON(asn.user_id = u.user_id) diff --git a/upload/includes/functions_post.php b/upload/includes/functions_post.php index e6b08ca20..4e053f26e 100644 --- a/upload/includes/functions_post.php +++ b/upload/includes/functions_post.php @@ -5,7 +5,7 @@ if (!defined('BB_ROOT')) die(basename(__FILE__)); // // Prepare a message for posting // -function prepare_post(&$mode, &$post_data, &$error_msg, &$username, &$subject, &$message, &$poll_title, &$poll_options, &$poll_length) +function prepare_post(&$mode, &$post_data, &$error_msg, &$username, &$subject, &$message) { global $bb_cfg, $user, $userdata, $lang; @@ -44,45 +44,11 @@ function prepare_post(&$mode, &$post_data, &$error_msg, &$username, &$subject, & { } - else if ($mode != 'delete' && $mode != 'poll_delete') + else if ($mode != 'delete') { $error_msg .= (!empty($error_msg)) ? '
' . $lang['EMPTY_MESSAGE'] : $lang['EMPTY_MESSAGE']; } - // - // Handle poll stuff - // - if ($mode == 'newtopic' || ($mode == 'editpost' && $post_data['first_post'])) - { - $poll_length = (isset($poll_length)) ? max(0, intval($poll_length)) : 0; - - if(!empty($poll_options)) - { - $temp_option_text = array(); - while(list($option_id, $option_text) = @each($poll_options)) - { - $option_text = trim($option_text); - if (!empty($option_text)) - { - $temp_option_text[$option_id] = clean_title($option_text); - } - } - - if (count($poll_options) < 2) - { - $error_msg .= (!empty($error_msg)) ? '
' . $lang['TO_FEW_POLL_OPTIONS'] : $lang['TO_FEW_POLL_OPTIONS']; - } - else if (count($poll_options) > $bb_cfg['max_poll_options']) - { - $error_msg .= (!empty($error_msg)) ? '
' . $lang['TO_MANY_POLL_OPTIONS'] : $lang['TO_MANY_POLL_OPTIONS']; - } - else if ($poll_title == '') - { - $error_msg .= (!empty($error_msg)) ? '
' . $lang['EMPTY_POLL_TITLE'] : $lang['EMPTY_POLL_TITLE']; - } - } - } - // Check smilies limit if ($bb_cfg['max_smilies']) { @@ -101,9 +67,9 @@ function prepare_post(&$mode, &$post_data, &$error_msg, &$username, &$subject, & } // -// Post a new topic/reply/poll or edit existing post/poll +// Post a new topic/reply or edit existing post/poll // -function submit_post($mode, &$post_data, &$message, &$meta, &$forum_id, &$topic_id, &$post_id, &$poll_id, &$topic_type, $post_username, $post_subject, $post_message, $poll_title, &$poll_options, &$poll_length, $update_post_time) +function submit_post($mode, &$post_data, &$message, &$meta, &$forum_id, &$topic_id, &$post_id, &$topic_type, $post_username, $post_subject, $post_message, $update_post_time) { global $userdata, $post_info, $is_auth, $bb_cfg, $lang, $datastore; @@ -155,15 +121,13 @@ function submit_post($mode, &$post_data, &$message, &$meta, &$forum_id, &$topic_ if ($mode == 'newtopic' || ($mode == 'editpost' && $post_data['first_post'])) { - $topic_vote = (!empty($poll_title) && count($poll_options) >= 2) ? 1 : 0; - $topic_dl_type = (isset($_POST['topic_dl_type']) && ($post_info['allow_reg_tracker'] || $is_auth['auth_mod'])) ? TOPIC_DL_TYPE_DL : TOPIC_DL_TYPE_NORMAL; $sql_insert = " INSERT INTO - " . BB_TOPICS . " (topic_title, topic_poster, topic_time, forum_id, topic_status, topic_type, topic_dl_type, topic_vote) + " . BB_TOPICS . " (topic_title, topic_poster, topic_time, forum_id, topic_status, topic_type, topic_dl_type) VALUES - ('$post_subject', " . $userdata['user_id'] . ", $current_time, $forum_id, " . TOPIC_UNLOCKED . ", $topic_type, $topic_dl_type, $topic_vote) + ('$post_subject', " . $userdata['user_id'] . ", $current_time, $forum_id, " . TOPIC_UNLOCKED . ", $topic_type, $topic_dl_type) "; $sql_update = " @@ -173,7 +137,6 @@ function submit_post($mode, &$post_data, &$message, &$meta, &$forum_id, &$topic_ topic_title = '$post_subject', topic_type = $topic_type, topic_dl_type = $topic_dl_type - ". ((@$post_data['edit_vote'] || !empty($poll_title)) ? ", topic_vote = ". $topic_vote : "") ." WHERE topic_id = $topic_id "; @@ -250,76 +213,6 @@ function submit_post($mode, &$post_data, &$message, &$meta, &$forum_id, &$topic_ } } - // - // Add poll - // - if (($mode == 'newtopic' || ($mode == 'editpost' && $post_data['edit_poll'])) && !empty($poll_title) && count($poll_options) >= 2) - { - $sql = (!$post_data['has_poll']) ? "INSERT INTO " . BB_VOTE_DESC . " (topic_id, vote_text, vote_start, vote_length) VALUES ($topic_id, '$poll_title', $current_time, " . ($poll_length * 86400) . ")" : "UPDATE " . BB_VOTE_DESC . " SET vote_text = '$poll_title', vote_length = " . ($poll_length * 86400) . " WHERE topic_id = $topic_id"; - if (!DB()->sql_query($sql)) - { - message_die(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql); - } - - $delete_option_sql = ''; - $old_poll_result = array(); - if ($mode == 'editpost' && $post_data['has_poll']) - { - $sql = "SELECT vote_option_id, vote_result - FROM " . BB_VOTE_RESULTS . " - WHERE vote_id = $poll_id - ORDER BY vote_option_id ASC"; - if (!($result = DB()->sql_query($sql))) - { - message_die(GENERAL_ERROR, 'Could not obtain vote data results for this topic', '', __LINE__, __FILE__, $sql); - } - - while ($row = DB()->sql_fetchrow($result)) - { - $old_poll_result[$row['vote_option_id']] = $row['vote_result']; - - if (!isset($poll_options[$row['vote_option_id']])) - { - $delete_option_sql .= ($delete_option_sql != '') ? ', ' . $row['vote_option_id'] : $row['vote_option_id']; - } - } - } - else - { - $poll_id = DB()->sql_nextid(); - } - - @reset($poll_options); - - $poll_option_id = 1; - while (list($option_id, $option_text) = each($poll_options)) - { - if (!empty($option_text)) - { - $option_text = DB()->escape(clean_title($option_text)); - $poll_result = ($mode == "editpost" && isset($old_poll_result[$option_id])) ? $old_poll_result[$option_id] : 0; - - $sql = ($mode != "editpost" || !isset($old_poll_result[$option_id])) ? "INSERT INTO " . BB_VOTE_RESULTS . " (vote_id, vote_option_id, vote_option_text, vote_result) VALUES ($poll_id, $poll_option_id, '$option_text', $poll_result)" : "UPDATE " . BB_VOTE_RESULTS . " SET vote_option_text = '$option_text', vote_result = $poll_result WHERE vote_option_id = $option_id AND vote_id = $poll_id"; - if (!DB()->sql_query($sql)) - { - message_die(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql); - } - $poll_option_id++; - } - } - - if ($delete_option_sql != '') - { - $sql = "DELETE FROM " . BB_VOTE_RESULTS . " - WHERE vote_option_id IN ($delete_option_sql) - AND vote_id = $poll_id"; - if (!DB()->sql_query($sql)) - { - message_die(GENERAL_ERROR, 'Error deleting pruned poll options', '', __LINE__, __FILE__, $sql); - } - } - } - meta_refresh(POST_URL ."$post_id#$post_id"); set_die_append_msg($forum_id, $topic_id); @@ -402,10 +295,6 @@ function update_post_stats($mode, $post_data, $forum_id, $topic_id, $post_id, $u $forum_update_sql .= ", forum_last_post_id = $post_id" . (($mode == 'newtopic') ? ", forum_topics = forum_topics $sign" : ""); $topic_update_sql = "topic_last_post_id = $post_id, topic_last_post_time = ". TIMENOW . (($mode == 'reply') ? ", topic_replies = topic_replies $sign" : ", topic_first_post_id = $post_id"); } - else - { - $topic_update_sql .= 'topic_vote = 0'; - } $sql = "UPDATE " . BB_FORUMS . " SET $forum_update_sql WHERE forum_id = $forum_id"; if (!DB()->sql_query($sql)) @@ -423,36 +312,17 @@ function update_post_stats($mode, $post_data, $forum_id, $topic_id, $post_id, $u message_die(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql); } } - - if ($mode != 'poll_delete') - { - $sql = "UPDATE " . BB_USERS . " - SET user_posts = user_posts $sign - WHERE user_id = $user_id"; - if (!DB()->sql_query($sql)) - { - message_die(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql); - } - } } // -// Delete a post/poll +// Delete a post // -function delete_post($mode, $post_data, &$message, &$meta, $forum_id, $topic_id, $post_id, $poll_id) +function delete_post($mode, $post_data, &$message, &$meta, $forum_id, $topic_id, $post_id) { global $lang; - if ($mode == 'poll_delete') - { - $message = $lang['POLL_DELETE']; - poll_delete($topic_id); - } - else - { - $message = $lang['DELETED']; - post_delete($post_id); - } + $message = $lang['DELETED']; + post_delete($post_id); set_die_append_msg($forum_id, $topic_id); } diff --git a/upload/includes/init_bb.php b/upload/includes/init_bb.php index f83e32a3f..bcf98fc6f 100644 --- a/upload/includes/init_bb.php +++ b/upload/includes/init_bb.php @@ -100,6 +100,7 @@ define('COOKIE_DATA', $c .'data'); define('COOKIE_FORUM', $c .'f'); define('COOKIE_MARK', $c .'mark_read'); define('COOKIE_TOPIC', $c .'t'); +define('COOKIE_PM', $c .'pm'); unset($c); define('COOKIE_SESSION', 0); @@ -261,6 +262,10 @@ define('POST_REPORT_REASON_URL', 'r'); define('MALE', 1); define('FEMALE', 2); +// Poll +# 1 - обычный опрос +define('POLL_FINISHED', 2); + // Torrents (reserved: -1) define('TOR_NOT_APPROVED', 0); // не проверено define('TOR_CLOSED', 1); // закрыто @@ -355,6 +360,8 @@ define('BB_EXTENSIONS', 'bb_extensions'); define('BB_FORUMS', 'bb_forums'); define('BB_GROUPS', 'bb_groups'); define('BB_LOG', 'bb_log'); +define('BB_POLL_USERS', 'bb_poll_users'); +define('BB_POLL_VOTES', 'bb_poll_votes'); define('BB_POSTS_SEARCH', 'bb_posts_search'); define('BB_POSTS', 'bb_posts'); define('BB_POSTS_TEXT', 'bb_posts_text'); @@ -378,9 +385,6 @@ define('BB_TOPICS', 'bb_topics'); define('BB_TOPICS_WATCH', 'bb_topics_watch'); define('BB_USER_GROUP', 'bb_user_group'); define('BB_USERS', 'bb_users'); -define('BB_VOTE_DESC', 'bb_vote_desc'); -define('BB_VOTE_RESULTS', 'bb_vote_results'); -define('BB_VOTE_USERS', 'bb_vote_voters'); define('BB_WORDS', 'bb_words'); define('TORRENT_EXT', 'torrent'); diff --git a/upload/language/lang_english/lang_main.php b/upload/language/lang_english/lang_main.php index c06d95c59..dc1d1b085 100644 --- a/upload/language/lang_english/lang_main.php +++ b/upload/language/lang_english/lang_main.php @@ -290,13 +290,13 @@ $lang['SEARCH_IN_TOPIC'] = 'search in topic...'; $lang['HIDE_IN_TOPIC'] = 'Hide'; $lang['SHOW'] = 'Show'; -$lang['AVATARS'] = 'avatars'; -$lang['RANK_IMAGES'] = 'rank images'; -$lang['POST_IMAGES'] = 'post images'; -$lang['SIGNATURES'] = 'signatures'; +$lang['AVATARS'] = 'Avatars'; +$lang['RANK_IMAGES'] = 'Rank images'; +$lang['POST_IMAGES'] = 'Post images'; +$lang['SIGNATURES'] = 'Signatures'; $lang['SPOILER'] = 'Spoiler'; -$lang['SHOW_OPENED'] = 'show opened'; -$lang['DOWNLOAD_PIC'] = 'downloadable pictures'; +$lang['SHOW_OPENED'] = 'Show opened'; +$lang['DOWNLOAD_PIC'] = 'Downloadable pictures'; $lang['MODERATE_TOPIC'] = 'Moderate this topic'; $lang['SELECT_POSTS_PER_PAGE'] = 'posts per page'; diff --git a/upload/language/lang_russian/lang_main.php b/upload/language/lang_russian/lang_main.php index 804d030ec..234098b63 100644 --- a/upload/language/lang_russian/lang_main.php +++ b/upload/language/lang_russian/lang_main.php @@ -290,13 +290,13 @@ $lang['SEARCH_IN_TOPIC'] = 'Искать в теме…'; $lang['HIDE_IN_TOPIC'] = 'Не показывать'; $lang['SHOW'] = 'Показывать'; -$lang['AVATARS'] = 'аватары'; -$lang['RANK_IMAGES'] = 'картинки званий'; -$lang['POST_IMAGES'] = 'картинки в сообщениях'; -$lang['SIGNATURES'] = 'подписи'; +$lang['AVATARS'] = 'Аватары'; +$lang['RANK_IMAGES'] = 'Картинки званий'; +$lang['POST_IMAGES'] = 'Картинки в сообщениях'; +$lang['SIGNATURES'] = 'Подписи'; $lang['SPOILER'] = 'Спойлер'; -$lang['SHOW_OPENED'] = 'спойлер открытым'; -$lang['DOWNLOAD_PIC'] = 'загружаемые картинки'; +$lang['SHOW_OPENED'] = 'Спойлер открытым'; +$lang['DOWNLOAD_PIC'] = 'Загружаемые картинки'; $lang['MODERATE_TOPIC'] = 'Модерировать этот топик'; $lang['SELECT_POSTS_PER_PAGE'] = 'сообщ. на страницу'; diff --git a/upload/poll.php b/upload/poll.php new file mode 100644 index 000000000..ba0e12d29 --- /dev/null +++ b/upload/poll.php @@ -0,0 +1,241 @@ +session_start(array('req_login' => true)); + +$mode = (string) @$_POST['mode']; +$topic_id = (int) @$_POST['topic_id']; +$forum_id = (int) @$_POST['forum_id']; +$vote_id = (int) @$_POST['vote_id']; + +$return_topic_url = TOPIC_URL . $topic_id; +$return_topic_url .= !empty($_POST['start']) ? "&start=". intval($_POST['start']) : ''; + +$template->assign_var('BB_DIE_APPEND_MSG', ' + Вернуться в тему +

+ Вернуться в раздел +

+ Вернуться на главную страницу +'); + +$poll = new bb_poll(); + +// проверка валидности $topic_id +if (!$topic_id) +{ + bb_die('Invalid topic_id'); +} +if (!$t_data = DB()->fetch_row("SELECT * FROM ". BB_TOPICS ." WHERE topic_id = $topic_id LIMIT 1")) +{ + bb_die('Тема не найдена'); +} + +// проверка прав +if ($mode != 'poll_vote') +{ + if ($t_data['topic_poster'] != $userdata['user_id']) + { + if (!IS_AM) bb_die('Нет прав'); + } +} + +// проверка на возможность вносить изменения +if ($mode != 'poll_delete') +{ + if ($t_data['topic_time'] < TIMENOW - $bb_cfg['poll_max_days']*86400) + { + bb_die("Время для этого опроса ({$bb_cfg['poll_max_days']} дней с момента создания темы) уже закончилось"); + } + if (!IS_ADMIN && ($t_data['topic_vote'] != POLL_FINISHED)) + { bb_die($lang['CANNOT_DELETE_POLL']); } +} + +switch ($mode) +{ + // голосование + case 'poll_vote': + if (!$t_data['topic_vote']) + { + bb_die('Опрос не найден'); + } + if ($t_data['topic_status'] == TOPIC_LOCKED) + { + bb_die($lang['TOPIC_LOCKED_SHORT']); + } + if (!poll_is_active($t_data)) + { + bb_die('Этот опрос уже завершён'); + } + if (!$vote_id) + { + bb_die('Вы не выбрали, за что голосуете'); + } + if (DB()->fetch_row("SELECT 1 FROM ". BB_POLL_USERS ." WHERE topic_id = $topic_id AND user_id = {$userdata['user_id']} LIMIT 1")) + { + bb_die($lang['TOPIC_LOCKED_SHORT']); + } + + DB()->query(" + UPDATE ". BB_POLL_VOTES ." SET + vote_result = vote_result + 1 + WHERE topic_id = $topic_id + AND vote_id = $vote_id + LIMIT 1 + "); + if (DB()->affected_rows() != 1) + { + bb_die('Вы не выбрали, за что голосуете'); + } + CACHE('bb_poll_data')->rm($topic_id, 'poll_'); + + DB()->query("INSERT IGNORE INTO ". BB_POLL_USERS ." (topic_id, user_id, vote_dt) VALUES ($topic_id, {$userdata['user_id']}, ". TIMENOW .")"); + + bb_die('Спасибо! Ваш голос учтён'); + break; + + // возобновить возможность голосовать + case 'poll_start': + if (!$t_data['topic_vote']) + { + bb_die('Опрос не найден'); + } + DB()->query("UPDATE ". BB_TOPICS ." SET topic_vote = 1 WHERE topic_id = $topic_id LIMIT 1"); + bb_die('Опрос включен'); + break; + + // завершить опрос + case 'poll_finish': + if (!$t_data['topic_vote']) + { + bb_die('Опрос не найден'); + } + DB()->query("UPDATE ". BB_TOPICS ." SET topic_vote = ". POLL_FINISHED ." WHERE topic_id = $topic_id LIMIT 1"); + bb_die('Опрос завершён'); + break; + + // удаление + case 'poll_delete': + if (!$t_data['topic_vote']) + { + bb_die('Опрос не найден'); + } + $poll->delete_poll($topic_id); + bb_die('Опрос удалён'); + break; + + // добавление + case 'poll_add': + if ($t_data['topic_vote']) + { + bb_die('Тема уже имеет опрос'); + } + $poll->build_poll_data($_POST); + if ($poll->err_msg) + { + bb_die($poll->err_msg); + } + $poll->insert_votes_into_db($topic_id); + bb_die('Опрос добавлен'); + break; + + // редакторование + case 'poll_edit': + if (!$t_data['topic_vote']) + { + bb_die('Опрос не найден'); + } + $poll->build_poll_data($_POST); + if ($poll->err_msg) + { + bb_die($poll->err_msg); + } + $poll->insert_votes_into_db($topic_id); + bb_die('Опрос изменён и старые результаты удалены'); + break; + + default: + bb_die("Invalid mode: ". htmlCHR($mode)); +} + +// ----------------------------------------------------------- // +// Functions +// + + +class bb_poll +{ + var $err_msg = ''; + var $poll_votes = array(); // array(vote_id => vote_text) + var $max_votes = 0; + + function bb_poll () + { + global $bb_cfg; + $this->max_votes = $bb_cfg['max_poll_options']; + } + + function build_poll_data ($posted_data) + { + $poll_caption = (string) @$posted_data['poll_caption']; + $poll_votes = (string) @$posted_data['poll_votes']; + $this->poll_votes = array(); + + if (!$poll_caption = str_compact($poll_caption)) + { + return $this->err_msg = 'Вы должны указать заголовок'; + } + $this->poll_votes[] = $poll_caption; // заголовок имеет vote_id = 0 + + foreach (explode("\n", $poll_votes) as $vote) + { + if (!$vote = str_compact($vote)) + { + continue; + } + $this->poll_votes[] = $vote; + } + + // проверять на "< 3" -- 2 варианта ответа + заголовок + if (count($this->poll_votes) < 3 || count($this->poll_votes) > $this->max_votes + 1) + { + return $this->err_msg = "Вы должны правильно указать варианты ответа (минимум 2, максимум {$this->max_votes})"; + } + } + + function insert_votes_into_db ($topic_id) + { + $this->delete_votes_data($topic_id); + + $sql_ary = array(); + foreach ($this->poll_votes as $vote_id => $vote_text) + { + $sql_ary[] = array( + 'topic_id' => (int) $topic_id, + 'vote_id' => (int) $vote_id, + 'vote_text' => (string) $vote_text, + 'vote_result' => (int) 0, + ); + } + $sql_args = DB()->build_array('MULTI_INSERT', $sql_ary); + + DB()->query("REPLACE INTO ". BB_POLL_VOTES . $sql_args); + + DB()->query("UPDATE ". BB_TOPICS ." SET topic_vote = 1 WHERE topic_id = $topic_id LIMIT 1"); + } + + function delete_poll ($topic_id) + { + DB()->query("UPDATE ". BB_TOPICS ." SET topic_vote = 0 WHERE topic_id = $topic_id LIMIT 1"); + $this->delete_votes_data($topic_id); + } + + function delete_votes_data ($topic_id) + { + DB()->query("DELETE FROM ". BB_POLL_VOTES ." WHERE topic_id = $topic_id"); + DB()->query("DELETE FROM ". BB_POLL_USERS ." WHERE topic_id = $topic_id"); + CACHE('bb_poll_data')->rm($topic_id, 'poll_'); + } +} \ No newline at end of file diff --git a/upload/posting.php b/upload/posting.php index f2af7b8b7..cdf1bf45a 100644 --- a/upload/posting.php +++ b/upload/posting.php @@ -15,9 +15,6 @@ $page_cfg['load_tpl_vars'] = array( $submit = (bool) @$_REQUEST['post']; $preview = (bool) @$_REQUEST['preview']; $delete = (bool) @$_REQUEST['delete']; -$poll_delete = (bool) @$_REQUEST['poll_delete']; -$poll_add = (bool) @$_REQUEST['add_poll_option']; -$poll_edit = (bool) @$_REQUEST['edit_poll_option']; $topic_tpl = (bool) @$_REQUEST['tpl']; $forum_id = (int) @$_REQUEST[POST_FORUM_URL]; @@ -28,9 +25,7 @@ $mode = (string) @$_REQUEST['mode']; $confirm = isset($_POST['confirm']); -$poll_id = null; - -$refresh = $preview || $poll_add || $poll_edit || $poll_delete; +$refresh = $preview; $orig_word = $replacement_word = array(); // Set topic type @@ -98,14 +93,9 @@ switch ($mode) break; case 'delete': - case 'poll_delete': $is_auth_type = 'auth_delete'; break; - case 'vote': - $is_auth_type = 'auth_vote'; - break; - default: message_die(GENERAL_MESSAGE, $lang['NO_POST_MODE']); break; @@ -126,7 +116,6 @@ switch ($mode) break; case 'reply': - case 'vote': if (!$topic_id) { message_die(GENERAL_MESSAGE, $lang['NO_TOPIC_ID']); @@ -141,7 +130,6 @@ switch ($mode) case 'quote': case 'editpost': case 'delete': - case 'poll_delete': if (!$post_id) { message_die(GENERAL_MESSAGE, $lang['NO_POST_ID']); @@ -186,7 +174,7 @@ if ($post_info = DB()->fetch_row($sql)) message_die(GENERAL_MESSAGE, $lang['TOPIC_LOCKED']); } - if ($mode == 'editpost' || $mode == 'delete' || $mode == 'poll_delete') + if ($mode == 'editpost' || $mode == 'delete') { $topic_id = $post_info['topic_id']; @@ -194,46 +182,10 @@ if ($post_info = DB()->fetch_row($sql)) $post_data['first_post'] = ($post_info['topic_first_post_id'] == $post_id); $post_data['last_post'] = ($post_info['topic_last_post_id'] == $post_id); $post_data['last_topic'] = ($post_info['forum_last_post_id'] == $post_id); - $post_data['has_poll'] = (bool) $post_info['topic_vote']; $post_data['topic_type'] = $post_info['topic_type']; $post_data['poster_id'] = $post_info['poster_id']; - if ($post_data['first_post'] && $post_data['has_poll']) - { - $sql = "SELECT * - FROM ". BB_VOTE_DESC ." vd, ". BB_VOTE_RESULTS ." vr - WHERE vd.topic_id = $topic_id - AND vr.vote_id = vd.vote_id - ORDER BY vr.vote_option_id"; - - if (!$result = DB()->sql_query($sql)) - { - message_die(GENERAL_ERROR, 'Could not obtain vote data for this topic', '', __LINE__, __FILE__, $sql); - } - - $poll_options = array(); - $poll_results_sum = 0; - if ($row = DB()->sql_fetchrow($result)) - { - $poll_title = $row['vote_text']; - $poll_id = $row['vote_id']; - $poll_length = $row['vote_length'] / 86400; - - do - { - $poll_options[$row['vote_option_id']] = $row['vote_option_text']; - $poll_results_sum += $row['vote_result']; - } - while ($row = DB()->sql_fetchrow($result)); - } - $post_data['edit_poll'] = ((!$poll_results_sum || $is_auth['auth_mod']) && $post_data['first_post']); - } - else - { - $post_data['edit_poll'] = ($post_data['first_post'] && $is_auth['auth_pollcreate']); - } - - // Can this user edit/delete the post/poll? + // Can this user edit/delete the post? if ($post_info['poster_id'] != $userdata['user_id'] && !$is_auth['auth_mod']) { $message = ($delete || $mode == 'delete') ? $lang['DELETE_OWN_POSTS'] : $lang['EDIT_OWN_POSTS']; @@ -242,11 +194,7 @@ if ($post_info = DB()->fetch_row($sql)) { $message = $lang['CANNOT_DELETE_REPLIED']; } - elseif (!$post_data['edit_poll'] && !$is_auth['auth_mod'] && ($mode == 'poll_delete' || $poll_delete)) - { - $message = $lang['CANNOT_DELETE_POLL']; - } - + set_die_append_msg($forum_id, $topic_id); if(isset($message)) bb_die($message); } @@ -262,12 +210,6 @@ if ($post_info = DB()->fetch_row($sql)) } $post_data['first_post'] = ($mode == 'newtopic'); $post_data['last_post'] = false; - $post_data['has_poll'] = false; - $post_data['edit_poll'] = false; - } - if ($mode == 'poll_delete' && !$poll_id) - { - message_die(GENERAL_MESSAGE, $lang['NO_SUCH_POST']); } } else @@ -391,7 +333,7 @@ if (!IS_GUEST && $mode != 'newtopic' && ($submit || $preview || $mode == 'quote' // -------------------- // What shall we do? // -if ( ( $delete || $poll_delete || $mode == 'delete' ) && !$confirm ) +if ( ( $delete || $mode == 'delete' ) && !$confirm ) { if (isset($_POST['cancel'])) { @@ -402,96 +344,19 @@ if ( ( $delete || $poll_delete || $mode == 'delete' ) && !$confirm ) // $hidden_fields = array( 'p' => $post_id, - 'mode' => ($delete || $mode == "delete") ? 'delete' : 'poll_delete', + 'mode' => 'delete', ); print_confirmation(array( - 'QUESTION' => ($delete || $mode == 'delete') ? $lang['CONFIRM_DELETE'] : $lang['CONFIRM_DELETE_POLL'], + 'QUESTION' => $lang['CONFIRM_DELETE'], 'FORM_ACTION' => POSTING_URL, 'HIDDEN_FIELDS' => build_hidden_fields($hidden_fields), )); } -elseif ( $mode == 'vote' ) -{ - // - // Vote in a poll - // - if ( !empty($_POST['vote_id']) ) - { - $vote_option_id = intval($_POST['vote_id']); - - $sql = "SELECT vd.vote_id - FROM " . BB_VOTE_DESC . " vd, " . BB_VOTE_RESULTS . " vr - WHERE vd.topic_id = $topic_id - AND vr.vote_id = vd.vote_id - AND vr.vote_option_id = $vote_option_id - GROUP BY vd.vote_id"; - if ( !($result = DB()->sql_query($sql)) ) - { - message_die(GENERAL_ERROR, 'Could not obtain vote data for this topic', '', __LINE__, __FILE__, $sql); - } - - if ( $vote_info = DB()->sql_fetchrow($result) ) - { - $vote_id = $vote_info['vote_id']; - - $sql = "SELECT * - FROM " . BB_VOTE_USERS . " - WHERE vote_id = $vote_id - AND vote_user_id = " . $userdata['user_id']; - if ( !($result2 = DB()->sql_query($sql)) ) - { - message_die(GENERAL_ERROR, 'Could not obtain user vote data for this topic', '', __LINE__, __FILE__, $sql); - } - - if ( !($row = DB()->sql_fetchrow($result2)) ) - { - $sql = "UPDATE " . BB_VOTE_RESULTS . " - SET vote_result = vote_result + 1 - WHERE vote_id = $vote_id - AND vote_option_id = $vote_option_id"; - if ( !DB()->sql_query($sql) ) - { - message_die(GENERAL_ERROR, 'Could not update poll result', '', __LINE__, __FILE__, $sql); - } - - $sql = "INSERT INTO " . BB_VOTE_USERS . " (vote_id, vote_user_id, vote_user_ip) - VALUES ($vote_id, " . $userdata['user_id'] . ", '". USER_IP ."')"; - if ( !DB()->sql_query($sql) ) - { - message_die(GENERAL_ERROR, "Could not insert user_id for poll", "", __LINE__, __FILE__, $sql); - } - - $message = $lang['VOTE_CAST']; - } - else - { - $message = $lang['ALREADY_VOTED']; - } - DB()->sql_freeresult($result2); - } - else - { - $message = $lang['NO_VOTE_OPTION']; - } - DB()->sql_freeresult($result); - - meta_refresh("viewtopic.php?" . POST_TOPIC_URL . "=$topic_id"); - $message .= '

' . sprintf($lang['CLICK_RETURN_TOPIC'], '', ''); - message_die(GENERAL_MESSAGE, $message); - } - else - { - redirect("viewtopic.php?" . POST_TOPIC_URL . "=$topic_id"); - } -} -//snp -// elseif ( $submit || $confirm ) elseif ( ($submit || $confirm) && !$topic_has_new_posts ) -//snp end { // - // Submit post/vote (newtopic, edit, reply, etc.) + // Submit post (newtopic, edit, reply, etc.) // $return_message = ''; $return_meta = ''; @@ -504,18 +369,15 @@ elseif ( ($submit || $confirm) && !$topic_has_new_posts ) $username = ( !empty($_POST['username']) ) ? clean_username($_POST['username']) : ''; $subject = ( !empty($_POST['subject']) ) ? clean_title($_POST['subject']) : ''; $message = ( !empty($_POST['message']) ) ? prepare_message($_POST['message']) : ''; - $poll_title = ( isset($_POST['poll_title']) && $is_auth['auth_pollcreate'] ) ? clean_title($_POST['poll_title']) : ''; - $poll_options = ( isset($_POST['poll_option_text']) && $is_auth['auth_pollcreate'] ) ? $_POST['poll_option_text'] : ''; - $poll_length = ( isset($_POST['poll_length']) && $is_auth['auth_pollcreate'] ) ? $_POST['poll_length'] : ''; - prepare_post($mode, $post_data, $error_msg, $username, $subject, $message, $poll_title, $poll_options, $poll_length); + prepare_post($mode, $post_data, $error_msg, $username, $subject, $message); if (!$error_msg) { $topic_type = ( isset($post_data['topic_type']) && $topic_type != $post_data['topic_type'] && !$is_auth['auth_sticky'] && !$is_auth['auth_announce'] ) ? $post_data['topic_type'] : $topic_type; - submit_post($mode, $post_data, $return_message, $return_meta, $forum_id, $topic_id, $post_id, $poll_id, $topic_type, DB()->escape($username), DB()->escape($subject), DB()->escape($message), DB()->escape($poll_title), $poll_options, $poll_length, $update_post_time); - + submit_post($mode, $post_data, $return_message, $return_meta, $forum_id, $topic_id, $post_id, $topic_type, DB()->escape($username), DB()->escape($subject), DB()->escape($message), $update_post_time); + $post_url = POST_URL ."$post_id#$post_id"; $post_msg = ($mode == 'editpost') ? $lang['EDITED']: $lang['STORED']; $onclick = ($mode == 'editpost') ? 'onclick="return post2url(this.href);"': ''; @@ -526,22 +388,21 @@ elseif ( ($submit || $confirm) && !$topic_has_new_posts ) break; case 'delete': - case 'poll_delete': require_once(INC_DIR .'functions_admin.php'); - delete_post($mode, $post_data, $return_message, $return_meta, $forum_id, $topic_id, $post_id, $poll_id); + delete_post($mode, $post_data, $return_message, $return_meta, $forum_id, $topic_id, $post_id); break; } if (!$error_msg) { - if (!in_array($mode, array('editpost', 'delete', 'poll_delete'))) + if (!in_array($mode, array('editpost', 'delete'))) { $user_id = ( $mode == 'reply' || $mode == 'newtopic' ) ? $userdata['user_id'] : $post_data['poster_id']; update_post_stats($mode, $post_data, $forum_id, $topic_id, $post_id, $user_id); } $attachment_mod['posting']->insert_attachment($post_id); - if (!$error_msg && $mode != 'poll_delete') + if (!$error_msg) { user_notification($mode, $post_data, $post_info['topic_title'], $forum_id, $topic_id, $post_id, $notify_user); } @@ -606,40 +467,12 @@ elseif ( ($submit || $confirm) && !$topic_has_new_posts ) } } -//snp -//if( $refresh || isset($_POST['del_poll_option']) || $error_msg != '' ) -if( $refresh || isset($_POST['del_poll_option']) || $error_msg || ($submit && $topic_has_new_posts) ) -//snp end +if( $refresh || $error_msg || ($submit && $topic_has_new_posts) ) { $username = ( !empty($_POST['username']) ) ? clean_username($_POST['username']) : ''; $subject = ( !empty($_POST['subject']) ) ? clean_title($_POST['subject']) : ''; $message = ( !empty($_POST['message']) ) ? prepare_message($_POST['message']) : ''; - $poll_title = ( !empty($_POST['poll_title']) ) ? clean_title($_POST['poll_title']) : ''; - $poll_length = ( isset($_POST['poll_length']) ) ? max(0, intval($_POST['poll_length'])) : 0; - - $poll_options = array(); - if ( !empty($_POST['poll_option_text']) ) - { -# while( list($option_id, $option_text) = @each($_POST['poll_option_text']) ) - foreach ($_POST['poll_option_text'] as $option_id => $option_text) - { - if (isset($_POST['del_poll_option'][$option_id])) - { - unset($poll_options[$option_id]); - } - elseif (!empty($option_text)) - { - $poll_options[$option_id] = clean_title($option_text); - } - } - } - - if ( $poll_add && !empty($_POST['add_poll_option_text']) ) - { - $poll_options[] = clean_title($_POST['add_poll_option_text']); - } - if ($preview) { $preview_subject = $subject; @@ -663,16 +496,12 @@ else if ( $mode == 'newtopic' ) { $username = ($userdata['session_logged_in']) ? $userdata['username'] : ''; - $poll_title = ''; - $poll_length = ''; - $subject = ''; - $message = ''; + $subject = $message = ''; } elseif ( $mode == 'reply' ) { $username = ( $userdata['session_logged_in'] ) ? $userdata['username'] : ''; - $subject = ''; - $message = ''; + $subject = $message = ''; } elseif ( $mode == 'quote' || $mode == 'editpost' ) { @@ -843,7 +672,6 @@ $template->set_filenames(array( // // Output the data to the template // - $template->assign_vars(array( 'FORUM_NAME' => htmlCHR($forum_name), 'PAGE_TITLE' => $page_title, @@ -880,35 +708,6 @@ if ($mode == 'editpost' && $post_data['last_post'] && !$post_data['first_post']) )); } -// -// Poll entry switch/output -// -if( ( $mode == 'newtopic' || ( $mode == 'editpost' && $post_data['edit_poll']) ) && $is_auth['auth_pollcreate'] ) -{ - $template->assign_vars(array( - 'POLL_TITLE' => @$poll_title, - 'POLL_LENGTH' => @$poll_length) - ); - - if( $mode == 'editpost' && $post_data['edit_poll'] && $post_data['has_poll']) - { - $template->assign_block_vars('switch_poll_delete_toggle', array()); - } - - if( !empty($poll_options) ) - { - while( list($option_id, $option_text) = each($poll_options) ) - { - $template->assign_block_vars('poll_option_rows', array( - 'POLL_OPTION' => str_replace('"', '"', $option_text), - 'S_POLL_OPTION_NUM' => $option_id) - ); - } - } - - $template->assign_var('POLLBOX'); -} - // // Topic review // diff --git a/upload/templates/default/viewtopic.tpl b/upload/templates/default/viewtopic.tpl index 03f536eb2..d73ec84fb 100644 --- a/upload/templates/default/viewtopic.tpl +++ b/upload/templates/default/viewtopic.tpl @@ -178,7 +178,64 @@ ajax.callback.post_mod_comment = function(data) { + + + + + + + + + + @@ -337,7 +394,7 @@ ajax.callback.post_mod_comment = function(data) {

{L_LONGEVITY}: {postrow.POSTER_JOINED}

{L_POSTS}: {postrow.POSTER_POSTS}

{L_LOCATION}: {postrow.POSTER_FROM}

- +

{postrow.POSTER_BIRTHDAY}

@@ -359,6 +416,7 @@ ajax.callback.post_mod_comment = function(data) {

{MC_IMG}{POST_BTN_SPACER} + {L_TOPIC_POLL}  {QUOTE_IMG}{POST_BTN_SPACER} {EDIT_POST_IMG}{POST_BTN_SPACER} {DELETE_POST_IMG}{POST_BTN_SPACER} diff --git a/upload/templates/default/viewtopic_poll.tpl b/upload/templates/default/viewtopic_poll.tpl index 966cf9cd1..cd6b44a8e 100644 --- a/upload/templates/default/viewtopic_poll.tpl +++ b/upload/templates/default/viewtopic_poll.tpl @@ -1,51 +1,151 @@ -

- - + + +
+ + + + + + + + + + + + + + + + + + + + +
+ +
+
+ + +
[ {L_SUBMIT_VOTE} ]
+ + +
[ Опрос завершён ]
+ + +
Всего проголосовало:
+ + +
+[ {L_DELETE_POLL} ]   + + [ {L_EDIT} ]   + + [ Включить опрос ]   + + [ Завершить опрос ]   + + +
+ diff --git a/upload/viewtopic.php b/upload/viewtopic.php index 3a37ac9c4..7db1b6a9d 100644 --- a/upload/viewtopic.php +++ b/upload/viewtopic.php @@ -279,10 +279,10 @@ if ($bb_cfg['topic_notify_enabled']) message_die(GENERAL_ERROR, "Could not delete topic watch information", '', __LINE__, __FILE__, $sql); } } - + set_die_append_msg($forum_id, $topic_id); bb_die($lang['NO_LONGER_WATCHING']); - + } else { @@ -319,7 +319,7 @@ if ($bb_cfg['topic_notify_enabled']) set_die_append_msg($forum_id, $topic_id); bb_die($lang['YOU_ARE_WATCHING']); - + } else { @@ -580,6 +580,11 @@ $sel_post_order_ary = array( $lang['NEWEST_FIRST'] => 'desc', ); +$topic_has_poll = ($t_data['topic_vote'] && !IS_GUEST); +$poll_time_expired = ($t_data['topic_time'] < TIMENOW - $bb_cfg['poll_max_days']*86400); +$can_manage_poll = ($t_data['topic_poster'] == $userdata['user_id'] || $is_auth['auth_mod']); +$can_add_poll = ($can_manage_poll && !$topic_has_poll && !$poll_time_expired && !$start); + // // Send vars to template // @@ -632,6 +637,11 @@ $template->assign_vars(array( 'U_POST_REPLY_TOPIC' => $reply_topic_url, 'U_SEARCH_SELF' => "search.php?uid={$userdata['user_id']}&t=$topic_id&dm=1", + 'TOPIC_HAS_POLL' => $topic_has_poll, + 'POLL_IS_EDITABLE' => (!$poll_time_expired), + 'POLL_IS_FINISHED' => ($t_data['topic_vote'] == POLL_FINISHED), + 'CAN_MANAGE_POLL' => $can_manage_poll, + 'CAN_ADD_POLL' => $can_add_poll, )); // Does this topic contain DL-List? @@ -642,134 +652,6 @@ $template->assign_vars(array( )); require(INC_DIR .'torrent_show_dl_list.php'); -// -// Does this topic contain a poll? -// -if ( !empty($t_data['topic_vote']) ) -{ - $s_hidden_fields = ''; - - $sql = "SELECT vd.vote_id, vd.vote_text, vd.vote_start, vd.vote_length, vr.vote_option_id, vr.vote_option_text, vr.vote_result - FROM " . BB_VOTE_DESC . " vd, " . BB_VOTE_RESULTS . " vr - WHERE vd.topic_id = $topic_id - AND vr.vote_id = vd.vote_id - ORDER BY vr.vote_option_id ASC"; - if ( !($result = DB()->sql_query($sql)) ) - { - message_die(GENERAL_ERROR, "Could not obtain vote data for this topic", '', __LINE__, __FILE__, $sql); - } - - if ( $vote_info = DB()->sql_fetchrowset($result) ) - { - DB()->sql_freeresult($result); - $vote_options = count($vote_info); - - $vote_id = $vote_info[0]['vote_id']; - $vote_title = $vote_info[0]['vote_text']; - - $sql = "SELECT vote_id - FROM " . BB_VOTE_USERS . " - WHERE vote_id = $vote_id - AND vote_user_id = " . intval($userdata['user_id']); - if ( !($result = DB()->sql_query($sql)) ) - { - message_die(GENERAL_ERROR, "Could not obtain user vote data for this topic", '', __LINE__, __FILE__, $sql); - } - - $user_voted = ( $row = DB()->sql_fetchrow($result) ) ? TRUE : 0; - DB()->sql_freeresult($result); - - if ( isset($_GET['vote']) || isset($_POST['vote']) ) - { - $view_result = ( ( ( isset($_GET['vote']) ) ? $_GET['vote'] : $_POST['vote'] ) == 'viewresult' ) ? TRUE : 0; - } - else - { - $view_result = 0; - } - - $poll_expired = ( $vote_info[0]['vote_length'] ) ? ( ( $vote_info[0]['vote_start'] + $vote_info[0]['vote_length'] < TIMENOW ) ? TRUE : 0 ) : 0; - - if ( $user_voted || $view_result || $poll_expired || !$is_auth['auth_vote'] || $t_data['topic_status'] == TOPIC_LOCKED ) - { - $vote_results_sum = 0; - - for($i = 0; $i < $vote_options; $i++) - { - $vote_results_sum += $vote_info[$i]['vote_result']; - } - - $vote_graphic = 0; - $vote_graphic_max = count($images['voting_graphic']); - - for($i = 0; $i < $vote_options; $i++) - { - $vote_percent = ( $vote_results_sum > 0 ) ? $vote_info[$i]['vote_result'] / $vote_results_sum : 0; - $vote_graphic_length = round($vote_percent * $bb_cfg['vote_graphic_length']); - - $vote_graphic_img = $images['voting_graphic'][$vote_graphic]; - $vote_graphic = ($vote_graphic < $vote_graphic_max - 1) ? $vote_graphic + 1 : 0; - - if ( count($orig_word) ) - { - $vote_info[$i]['vote_option_text'] = preg_replace($orig_word, $replacement_word, $vote_info[$i]['vote_option_text']); - } - - $template->assign_block_vars("poll_option", array( - 'POLL_OPTION_CAPTION' => $vote_info[$i]['vote_option_text'], - 'POLL_OPTION_RESULT' => $vote_info[$i]['vote_result'], - 'POLL_OPTION_PERCENT' => sprintf("%.1d%%", ($vote_percent * 100)), - - 'POLL_OPTION_IMG' => $vote_graphic_img, - 'POLL_OPTION_IMG_WIDTH' => $vote_graphic_length) - ); - } - - $template->assign_vars(array( - 'TPL_POLL_RESULT' => true, - 'TOTAL_VOTES' => $vote_results_sum, - )); - } - else - { - for($i = 0; $i < $vote_options; $i++) - { - if ( count($orig_word) ) - { - $vote_info[$i]['vote_option_text'] = preg_replace($orig_word, $replacement_word, $vote_info[$i]['vote_option_text']); - } - - $template->assign_block_vars("poll_option", array( - 'POLL_OPTION_ID' => $vote_info[$i]['vote_option_id'], - 'POLL_OPTION_CAPTION' => $vote_info[$i]['vote_option_text']) - ); - } - - $template->assign_vars(array( - 'TPL_POLL_BALLOT' => true, - 'U_VIEW_RESULTS' => TOPIC_URL ."$topic_id&vote=viewresult", - )); - - $s_hidden_fields = ''; - } - - if ( count($orig_word) ) - { - $vote_title = preg_replace($orig_word, $replacement_word, $vote_title); - } - - $s_hidden_fields .= ''; - - $template->assign_vars(array( - 'TOPIC_HAS_POLL' => true, - 'POLL_QUESTION' => $vote_title, - - 'S_HIDDEN_FIELDS' => $s_hidden_fields, - 'S_POLL_ACTION' => POSTING_URL . "?mode=vote&t=$topic_id", - )); - } -} - if ($t_data['topic_attachment']) { require(BB_ROOT .'attach_mod/attachment_mod.php'); @@ -790,6 +672,29 @@ if ( !DB()->sql_query($sql) ) message_die(GENERAL_ERROR, "Could not update topic views.", '', __LINE__, __FILE__, $sql); } +// +// Does this topic contain a poll? +// +if ($topic_has_poll) +{ + $poll_votes_js = CACHE('bb_poll_data')->get($topic_id, 'get_poll_data_items_js', 'poll_'); + + if (!$poll_votes_js) + { + $template->assign_vars(array( + 'TOPIC_HAS_POLL' => false, + )); + bb_log(join("\t", array(date('m-d H:i:s'), $topic_id, "\n")), 'poll_err'); + } + else + { + $template->assign_vars(array( + 'SHOW_VOTE_BTN' => poll_is_active($t_data), + 'POLL_VOTES_JS' => $poll_votes_js, + )); + } +} + $prev_post_time = $max_post_time = 0; // Report