mirror of
https://github.com/torrentpier/torrentpier
synced 2025-08-19 21:03:54 -07:00
r575
Новый опросник, начало обновления структуры лс и постов. Запрос для обновления: 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
This commit is contained in:
parent
9efc9409a8
commit
6c85e96e1c
15 changed files with 720 additions and 626 deletions
|
@ -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`
|
||||
--
|
||||
|
|
59
upgrade/r575-poll_upgrade.php
Normal file
59
upgrade/r575-poll_upgrade.php
Normal file
|
@ -0,0 +1,59 @@
|
|||
<?php
|
||||
|
||||
define('IN_FORUM', true);
|
||||
define('BB_ROOT', './');
|
||||
require(BB_ROOT .'common.php');
|
||||
|
||||
$user->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('<h1 style="color: green">База данных обновлена</h1>');
|
||||
}
|
||||
else
|
||||
{
|
||||
$msg = '<form method="POST">';
|
||||
$msg .= '<h1 style="color: red">!!! Перед тем как нажать на кнопку, сделайте бекап базы данных !!!</h1><br />';
|
||||
$msg .= '<input type="submit" name="confirm" value="Начать обновление Базы Данных (R575)" style="height: 30px; font:bold 14px Arial, Helvetica, sans-serif;" />';
|
||||
$msg .= '</form>';
|
||||
|
||||
bb_die($msg);
|
||||
}
|
|
@ -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')
|
||||
{
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
|
@ -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)
|
||||
|
|
|
@ -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)) ? '<br />' . $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)) ? '<br />' . $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)) ? '<br />' . $lang['TO_MANY_POLL_OPTIONS'] : $lang['TO_MANY_POLL_OPTIONS'];
|
||||
}
|
||||
else if ($poll_title == '')
|
||||
{
|
||||
$error_msg .= (!empty($error_msg)) ? '<br />' . $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);
|
||||
}
|
||||
|
||||
set_die_append_msg($forum_id, $topic_id);
|
||||
}
|
||||
|
|
|
@ -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');
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -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'] = 'сообщ. на страницу';
|
||||
|
|
241
upload/poll.php
Normal file
241
upload/poll.php
Normal file
|
@ -0,0 +1,241 @@
|
|||
<?php
|
||||
|
||||
define('BB_SCRIPT', 'vote');
|
||||
require('./common.php');
|
||||
|
||||
$user->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', '
|
||||
<a href="'. $return_topic_url .'">Вернуться в тему</a>
|
||||
<br /><br />
|
||||
<a href="viewforum.php?f='. $forum_id .'">Вернуться в раздел</a>
|
||||
<br /><br />
|
||||
<a href="index.php">Вернуться на главную страницу</a>
|
||||
');
|
||||
|
||||
$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_');
|
||||
}
|
||||
}
|
|
@ -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,10 +194,6 @@ 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 .= '<br /><br />' . sprintf($lang['CLICK_RETURN_TOPIC'], '<a href="' . ("viewtopic.php?" . POST_TOPIC_URL . "=$topic_id") . '">', '</a>');
|
||||
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,17 +369,14 @@ 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'];
|
||||
|
@ -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
|
||||
//
|
||||
|
|
|
@ -178,7 +178,64 @@ ajax.callback.post_mod_comment = function(data) {
|
|||
|
||||
<!-- IF SHOW_DL_LIST || SHOW_TOR_ACT --><!-- INCLUDE viewtopic_torrent.tpl --><!-- ENDIF -->
|
||||
|
||||
<!-- IF TOPIC_HAS_POLL or CAN_MANAGE_POLL -->
|
||||
<form id="poll-form" method="post" action="poll.php" style="display: none;">
|
||||
<input id="poll-mode" type="hidden" name="mode" value="" />
|
||||
<input type="hidden" name="topic_id" value="{TOPIC_ID}" />
|
||||
<input type="hidden" name="{TOPIC_HASH}" value="1" />
|
||||
<input type="hidden" name="start" value="{START}" />
|
||||
<input type="hidden" name="forum_id" value="{FORUM_ID}" />
|
||||
<input id="vote-id" type="hidden" name="vote_id" value="-1" />
|
||||
<input id="poll-submit-btn" type="submit" name="submit" value="1" />
|
||||
<input id="poll-caption-val" name="poll_caption" type="hidden" value="" />
|
||||
<textarea id="poll-votes-val" name="poll_votes" rows="10" cols="10"></textarea>
|
||||
</form>
|
||||
<!-- ENDIF -->
|
||||
<!-- IF CAN_MANAGE_POLL -->
|
||||
<script type="text/javascript">
|
||||
// заполняет #poll-form и отправляет запрос
|
||||
function poll_manage (mode, confirm_msg)
|
||||
{
|
||||
if (confirm_msg != null && !window.confirm( confirm_msg )) {
|
||||
return false;
|
||||
}
|
||||
$('#poll-mode').val(mode);
|
||||
$('#poll-caption-val').val( $('#poll-caption-inp').val() );
|
||||
$('#poll-votes-val').val( $('#poll-votes-inp').val() );
|
||||
$('#poll-submit-btn').click();
|
||||
return false;
|
||||
}
|
||||
|
||||
function build_poll_add_form (src_el)
|
||||
{
|
||||
$('#poll').empty().append( $('#poll-edit-tpl').contents() ).show();
|
||||
$('#poll-legend').html('Добавить опрос');
|
||||
$('#poll-edit-submit-btn').click(function(){
|
||||
return poll_manage('poll_add');
|
||||
});
|
||||
$(src_el).remove();
|
||||
return false;
|
||||
}
|
||||
</script>
|
||||
<div id="poll-edit-tpl" style="display: none;">
|
||||
<table class="med bCenter"><tr><td>
|
||||
<fieldset style="padding: 0 8px;">
|
||||
<legend id="poll-legend"></legend>
|
||||
<div style="margin-top: 4px;">заголовок опроса:</div>
|
||||
<input id="poll-caption-inp" name="poll_caption" type="text" value="" class="bold" style="width: 550px;" />
|
||||
<div class="med" style="margin-top: 4px;">варианты ответа:</div>
|
||||
<textarea id="poll-votes-inp" rows="8" cols="10" wrap="off" class="gen" style="width: 550px;"></textarea>
|
||||
<div class="med mrg_4"><i>каждая строка соответствует одному варианту ответа (максимум: {$bb_cfg['max_poll_options']} вариантов)</i></div>
|
||||
<div class="mrg_8 tCenter"><input id="poll-edit-submit-btn" type="button" value="Отправить" class="bold" style="width: 100px;" /></div>
|
||||
</fieldset>
|
||||
</td></tr></table>
|
||||
</div>
|
||||
<!-- ENDIF -->
|
||||
<!-- IF TOPIC_HAS_POLL or CAN_ADD_POLL -->
|
||||
<div id="poll" class="row5" style="padding: 0 10%; display: none;">
|
||||
<!-- IF TOPIC_HAS_POLL --><!-- INCLUDE viewtopic_poll.tpl --><!-- ENDIF -->
|
||||
</div>
|
||||
<!-- ENDIF -->
|
||||
|
||||
<table class="w100 border bw_TRL" cellpadding="0" cellspacing="0">
|
||||
<tr>
|
||||
|
@ -359,6 +416,7 @@ ajax.callback.post_mod_comment = function(data) {
|
|||
|
||||
<p style="float: right;<!-- IF TEXT_BUTTONS --> padding: 3px 2px 4px;<!-- ELSE --> padding: 1px 6px 2px;<!-- ENDIF -->" class="post_btn_1">
|
||||
<!-- IF AUTH_MOD --><a class="txtb menu-root mc_b" href="#mc_{postrow.POST_ID}">{MC_IMG}</a>{POST_BTN_SPACER}<!-- ENDIF -->
|
||||
<!-- IF postrow.IS_FIRST_POST and CAN_ADD_POLL --><a href="#" onclick="return build_poll_add_form(this);" class="txtb">{L_TOPIC_POLL}</a> <!-- ENDIF -->
|
||||
<!-- IF postrow.QUOTE --><a class="txtb" href="<!-- IF $bb_cfg['use_ajax_posts'] -->" onclick="ajax.exec({ action: 'posts', post_id: {postrow.POST_ID}, type: 'reply'}); return false;<!-- ELSE -->{QUOTE_URL}{postrow.POST_ID}<!-- ENDIF -->">{QUOTE_IMG}</a>{POST_BTN_SPACER}<!-- ENDIF -->
|
||||
<!-- IF postrow.EDIT --><a class="txtb" href="<!-- IF $bb_cfg['use_ajax_posts'] -->" onclick="edit_post({postrow.POST_ID}, 'edit'); return false;<!-- ELSE -->{EDIT_POST_URL}{postrow.POST_ID}<!-- ENDIF -->">{EDIT_POST_IMG}</a>{POST_BTN_SPACER}<!-- ENDIF -->
|
||||
<!-- IF postrow.DELETE --><a class="txtb" href="<!-- IF $bb_cfg['use_ajax_posts'] -->" onclick="ajax.exec({ action: 'posts', post_id: {postrow.POST_ID}, type: 'delete'}); return false;<!-- ELSE -->{DELETE_POST_URL}{postrow.POST_ID}<!-- ENDIF -->">{DELETE_POST_IMG}</a>{POST_BTN_SPACER}<!-- ENDIF -->
|
||||
|
|
|
@ -1,51 +1,151 @@
|
|||
<div id="poll" class="row5" style="padding: 0 10%;">
|
||||
|
||||
<!-- IF TPL_POLL_BALLOT -->
|
||||
<!--========================================================================-->
|
||||
<script type="text/javascript">
|
||||
var bb_poll = {};
|
||||
bb_poll.data = {POLL_VOTES_JS}; // [["заголовок", "result"], ...]
|
||||
bb_poll.title = '';
|
||||
bb_poll.votes_data = {};
|
||||
bb_poll.votes_sum = 0;
|
||||
bb_poll.max_img_len = 205; // 100% = this length
|
||||
|
||||
<form method="POST" action="{S_POLL_ACTION}">
|
||||
{S_HIDDEN_FIELDS}
|
||||
$(function(){
|
||||
$.each(bb_poll.data, function(vote_id, vote_data){
|
||||
var vote_text = vote_data[0];
|
||||
var vote_result = parseInt(vote_data[1]);
|
||||
|
||||
<p class="mrg_12 tCenter"><b>{POLL_QUESTION}</b></p>
|
||||
if (vote_id == 0) {
|
||||
bb_poll.title = vote_text;
|
||||
}
|
||||
else {
|
||||
bb_poll.votes_sum += vote_result;
|
||||
bb_poll.votes_data[vote_id] = [vote_text, vote_result];
|
||||
}
|
||||
});
|
||||
|
||||
<table cellpadding="0" class="borderless bCenter">
|
||||
<!-- BEGIN poll_option -->
|
||||
$('#poll-title').html(bb_poll.title);
|
||||
$('#votes-sum-val').text(bb_poll.votes_sum);
|
||||
|
||||
$.each(bb_poll.votes_data, function(vote_id, vote_data){
|
||||
var vote_caption = vote_data[0];
|
||||
var vote_result = parseInt(vote_data[1]);
|
||||
var vote_percent = (bb_poll.votes_sum) ? Math.round(vote_result / bb_poll.votes_sum * 100) : 0;
|
||||
var vote_img_width = Math.round(vote_percent * bb_poll.max_img_len / 100);
|
||||
|
||||
$('#poll-results-tpl tbody')
|
||||
.clone()
|
||||
.find('span.poll-vote-caption').html(vote_caption).end()
|
||||
.find('img.poll-vote-img').css({ width: vote_img_width }).end()
|
||||
.find('span.poll-vote-percent').text(vote_percent+'%').end()
|
||||
.find('span.poll-vote-result').text(vote_result).end()
|
||||
.appendTo('#poll-results-block')
|
||||
;
|
||||
});
|
||||
|
||||
$('#poll').show();
|
||||
});
|
||||
|
||||
function build_votes ()
|
||||
{
|
||||
$.each(bb_poll.votes_data, function(vote_id, vote_data){
|
||||
var vote_caption = vote_data[0];
|
||||
var vote_el_id = 'vote-'+ vote_id;
|
||||
|
||||
$('#poll-results-block').hide();
|
||||
$('#poll-votes-tpl tbody')
|
||||
.clone()
|
||||
.find('input').val(vote_id).attr({id: vote_el_id}).end()
|
||||
.find('label').html(vote_caption).attr({'for': vote_el_id}).end()
|
||||
.appendTo('#poll-votes-block')
|
||||
;
|
||||
});
|
||||
$('#votes-sum-block, #vote-btn-a, #poll-manage').hide();
|
||||
$('#vote-btn-input').show();
|
||||
}
|
||||
|
||||
function submit_vote ()
|
||||
{
|
||||
var $voted_id = $('input.vote-inp:checked');
|
||||
|
||||
if ($voted_id.length == 0) {
|
||||
alert('Вы не выбрали, за что голосуете');
|
||||
}
|
||||
else {
|
||||
$('#poll-mode').val('poll_vote');
|
||||
$voted_id.clone().appendTo('#poll-form');
|
||||
$('#vote-id').val( $voted_id.val() );
|
||||
$('#poll-submit-btn').click();
|
||||
}
|
||||
}
|
||||
|
||||
function build_poll_edit_form ()
|
||||
{
|
||||
$('#poll').empty().append( $('#poll-edit-tpl').contents() )
|
||||
$('#poll-legend').html('Изменить опрос');
|
||||
$('#poll-edit-submit-btn').click(function(){
|
||||
return poll_manage('poll_edit', 'Изменить опрос (старые результаты будут удалены)?');
|
||||
});
|
||||
|
||||
$('#poll-caption-inp').val( html2text(bb_poll.title) );
|
||||
|
||||
var votes_text = [];
|
||||
$.each(bb_poll.votes_data, function(vote_id, vote_data){
|
||||
votes_text.push( html2text(vote_data[0]) );
|
||||
});
|
||||
$('#poll-votes-inp').val( votes_text.join('\n') );
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function html2text (str)
|
||||
{
|
||||
return $('<span></span>').html(str).text();
|
||||
}
|
||||
</script>
|
||||
|
||||
<table id="poll-votes-tpl" style="display: none;">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td><input type="radio" name="vote_id" id="vote_{poll_option.POLL_OPTION_ID}" value="{poll_option.POLL_OPTION_ID}" /></td>
|
||||
<td><label for="vote_{poll_option.POLL_OPTION_ID}" class="wrap">{poll_option.POLL_OPTION_CAPTION}</label></td>
|
||||
<td><input type="radio" name="vote_id" class="vote-inp" value="" /></td>
|
||||
<td><label class="wrap"></label></td>
|
||||
</tr>
|
||||
<!-- END poll_option -->
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<p class="mrg_6 tCenter"><input type="submit" name="submit" value="{L_SUBMIT_VOTE}" class="liteoption" /></p>
|
||||
|
||||
<p class="small mrg_8 tCenter"><b><a href="{U_VIEW_RESULTS}" class="small">{L_VIEW_RESULTS}</a></b></p>
|
||||
|
||||
</form>
|
||||
|
||||
<!--========================================================================-->
|
||||
<!-- ENDIF / TPL_POLL_BALLOT -->
|
||||
|
||||
<!-- IF TPL_POLL_RESULT -->
|
||||
<!--========================================================================-->
|
||||
|
||||
<p class="mrg_12 tCenter"><b>{POLL_QUESTION}</b></p>
|
||||
|
||||
<table class="borderless bCenter">
|
||||
<!-- BEGIN poll_option -->
|
||||
<table id="poll-results-tpl" style="display: none;">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td class="tLeft">{poll_option.POLL_OPTION_CAPTION}</td>
|
||||
<td class="tLeft"><span class="poll-vote-caption"></span></td>
|
||||
<td> </td>
|
||||
<td class="nowrap"><img src="{IMG}vote_lcap.gif" width="4" alt="" height="12" /><img src="{poll_option.POLL_OPTION_IMG}" width="{poll_option.POLL_OPTION_IMG_WIDTH}" height="12" alt="{poll_option.POLL_OPTION_PERCENT}" /><img src="{IMG}vote_rcap.gif" width="4" alt="" height="12" /></td>
|
||||
<td class="nowrap tRight"><b> {poll_option.POLL_OPTION_PERCENT} </b></td>
|
||||
<td class="nowrap tCenter">[ {poll_option.POLL_OPTION_RESULT} ]</td>
|
||||
<td class="nowrap"><img src="{IMG}/vote_lcap.gif" width="4" height="12" alt="" /><img src="{IMG}/voting_bar.gif" class="poll-vote-img" width="1" height="12" alt="" /><img src="{IMG}/vote_rcap.gif" width="4" height="12" alt="" /></td>
|
||||
<td class="nowrap tRight bold"> <span class="poll-vote-percent"></span> </td>
|
||||
<td class="nowrap tCenter">[ <span class="poll-vote-result"></span> ]</td>
|
||||
</tr>
|
||||
<!-- END poll_option -->
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<p class="mrg_8 tCenter"><b>{L_TOTAL_VOTES} : {TOTAL_VOTES}</b></p>
|
||||
<div class="mrg_12 tCenter"><b id="poll-title"></b></div>
|
||||
|
||||
<!--========================================================================-->
|
||||
<!-- ENDIF / TPL_POLL_RESULT -->
|
||||
<table id="poll-results-block" class="borderless bCenter"></table>
|
||||
<table id="poll-votes-block" class="borderless bCenter"></table>
|
||||
|
||||
<!-- IF SHOW_VOTE_BTN -->
|
||||
<div id="vote-btn-a" class="mrg_8 tCenter">[ <a href="#" onclick="build_votes(); return false;" class="gen"><b>{L_SUBMIT_VOTE}</b></a> ]</div>
|
||||
<div id="vote-btn-input" class="mrg_6 tCenter" style="display: none;"><input type="button" onclick="submit_vote(); return false;" value="{L_SUBMIT_VOTE}" class="bold" /></div>
|
||||
<!-- ELSE -->
|
||||
<div class="mrg_8 tCenter">[ <b>Опрос завершён</b> ]</div>
|
||||
<!-- ENDIF -->
|
||||
|
||||
<div id="votes-sum-block" class="mrg_8 tCenter">Всего проголосовало: <span id="votes-sum-val"></span><b></b></div>
|
||||
|
||||
<!-- IF CAN_MANAGE_POLL -->
|
||||
<div id="poll-manage" class="mrg_8 tCenter">
|
||||
[ <a href="#" onclick="return poll_manage('poll_delete', '{L_CONFIRM_DELETE_POLL}');" class="med">{L_DELETE_POLL}</a> ]
|
||||
<!-- IF POLL_IS_EDITABLE -->
|
||||
[ <a href="#" onclick="return build_poll_edit_form();" class="med">{L_EDIT}</a> ]
|
||||
<!-- IF POLL_IS_FINISHED -->
|
||||
[ <a href="#" onclick="return poll_manage('poll_start', 'Включить опрос?');" class="med">Включить опрос</a> ]
|
||||
<!-- ELSE -->
|
||||
[ <a href="#" onclick="return poll_manage('poll_finish', 'Завершить опрос?');" class="med">Завершить опрос</a> ]
|
||||
<!-- ENDIF -->
|
||||
<!-- ENDIF -->
|
||||
</div>
|
||||
<!-- ENDIF -->
|
||||
|
|
|
@ -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 = '<input type="hidden" name="topic_id" value="' . $topic_id . '" /><input type="hidden" name="mode" value="vote" />';
|
||||
}
|
||||
|
||||
if ( count($orig_word) )
|
||||
{
|
||||
$vote_title = preg_replace($orig_word, $replacement_word, $vote_title);
|
||||
}
|
||||
|
||||
$s_hidden_fields .= '<input type="hidden" name="sid" value="' . $userdata['session_id'] . '" />';
|
||||
|
||||
$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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue