-- сделать запросы
- SQL
INSERT INTO `bb_config` VALUES ('poll_index', '');
INSERT INTO `bb_config` VALUES ('poll_name', '');
INSERT INTO `bb_config` VALUES ('poll_vote', '');
INSERT INTO `bb_config` VALUES ('poll_users', '');
INSERT INTO `bb_config` VALUES ('poll_result', '');
ALTER TABLE `bb_users` ADD `poll_index` TINYINT( 1 ) NOT NULL DEFAULT '0';
-- ajax.php
- найти
'index_data' => array('guest'),
- после добавить
'poll_index' => array('guest'),
- найти последнюю скобку
}
- перед добавить
function poll_index()
{
global $userdata, $lang, $bb_cfg, $images;
$mode = (string) $this->request['mode'];
switch($mode)
{
case 'poll':
if(!$bb_cfg['poll_vote']) bb_die($lang['NO_POLL']);
if(!empty($userdata['poll_index']) || (!empty($_COOKIE['poll_index']) && IS_GUEST)) bb_die($lang['ALREADY_VOTED']);
$poll = (int) $this->request['poll'];
$poll_vote = unserialize($bb_cfg['poll_vote']);
$poll_users = unserialize($bb_cfg['poll_users']);
$poll_result = unserialize($bb_cfg['poll_result']);
$vote_results_sum = 0;
foreach($poll_vote as $i => $row)
{
if(!$row) continue;
if($i == $poll) $poll_users[$i] = !empty($poll_users[$i]) ? ($poll_users[$i] + 1) : 1;
if($i == $poll) $poll_result[$i] = !empty($poll_result[$i]) ? ($poll_result[$i] + 1) : 1;
$vote_results_sum += !empty($poll_result[$i]) ? $poll_result[$i] : 0;
}
bb_update_config(array(
'poll_users' => serialize($poll_users),
'poll_result' => serialize($poll_result),
));
if(!IS_GUEST)
{
DB()->query("UPDATE ". BB_USERS ." SET poll_index = 1 WHERE user_id = ". $userdata['user_id']);
cache_rm_user_sessions ($userdata['user_id']);
}
$html = '';
foreach($poll_vote as $i => $row)
{
if(!$row) continue;
$users = !empty($poll_users[$i]) ? $poll_users[$i]: 0;
$result = !empty($poll_result[$i]) ? $poll_result[$i]: 0;
$vote_percent = ( $vote_results_sum > 0 ) ? $result / $vote_results_sum : 0;
$vote_graphic_length = round($vote_percent * 190);
$html .= '
'. $row .'
'. sprintf("%.1d%%", ($vote_percent * 100)) .' ['. $users .']
';
}
$this->response['html'] = $html;
break;
case 'delete':
bb_update_config(array(
'poll_name' => '',
'poll_vote' => '',
'poll_users' => '',
'poll_result' => '',
));
DB()->query("UPDATE ". BB_USERS ." SET poll_index = 0");
bb_die($lang['POLL_DELETED']);
break;
}
}
-- page_header.php
- найти
'U_SEARCH_SELF_BY_LAST' => "search.php?uid={$userdata['user_id']}&o=5",
));
- после добавить
if($bb_cfg['poll_index'] && !empty($page_cfg['show_sidebar1'][BB_SCRIPT]))
{
$template->assign_vars(array(
'POLL_NAME' => $bb_cfg['poll_name'],
'POLL_ENABLED' => true,
));
$poll_vote = unserialize($bb_cfg['poll_vote']);
$poll_users = unserialize($bb_cfg['poll_users']);
$poll_result = unserialize($bb_cfg['poll_result']);
if(!$bb_cfg['poll_vote'])
{
$template->assign_vars(array(
'POLL_ENABLED' => false,
));
}
elseif(!empty($userdata['poll_index']) || (!empty($_COOKIE['poll_index']) && IS_GUEST))
{
$vote_results_sum = 0;
foreach($poll_vote as $i => $row)
{
if(!$row) continue;
$vote_results_sum += !empty($poll_result[$i]) ? $poll_result[$i]: 0;
}
foreach($poll_vote as $i => $row)
{
if(!$row) continue;
$poll = !empty($poll_result[$i]) ? $poll_result[$i]: 0;
$vote_percent = ( $vote_results_sum > 0 ) ? $poll / $vote_results_sum : 0;
$vote_graphic_length = round($vote_percent * 190);
$template->assign_block_vars('poll_result', array(
'ID' => $i,
'OPTION' => $row,
'LENGTH' => $vote_graphic_length,
'PERCENT' => sprintf("%.1d%%", ($vote_percent * 100)),
'USERS' => !empty($poll_users[$i]) ? $poll_users[$i]: 0,
));
}
}
else
{
foreach($poll_vote as $i => $row)
{
if(!$row) continue;
$template->assign_block_vars('poll', array(
'ID' => $i,
'OPTION' => $row,
));
}
}
}
-- page_header.tpl
- добавить в sidebar
{L_POLL}
{POLL_NAME}
{L_NO_POLL}
админка
-- admin/admin_board.php
- найти
bb_update_config(array($config_name => $new[$config_name]));
- перед добавить
if($config_name == 'poll_vote') $new[$config_name] = serialize($new[$config_name]);
- найти
'SEED_BONUS_USER_REGDATE' => $new['seed_bonus_user_regdate'],
));
- заменить на
'SEED_BONUS_USER_REGDATE' => $new['seed_bonus_user_regdate'],
'POLL_NAME' => $new['poll_name'],
'POLL_ENABLED' => $new['poll_index'],
));
if($new['poll_vote'])
{
foreach(unserialize($new['poll_vote']) as $i => $row)
{
if(!$row) continue;
$template->assign_block_vars('poll', array(
'ID' => $i,
'OPTION' => $row,
));
}
}
-- admin/admin_board.tpl
- найти
{L_NEWS_FORUM_ID}
- после вставить
{L_POLL_ON_INDEX}
{L_POLL_ON_INDEX}
checked="checked" />{L_ENABLED}
checked="checked" />{L_DISABLED}
{L_POLL_QUESTION}
{L_ADD_OPTION}
{L_ADD_OPTION}
lang_main.php
// Опрос на главной
$lang['POLL'] = 'Опрос';
$lang['POLL_ON_INDEX'] = 'Опрос на главной';
$lang['NO_POLL'] = 'В данный момент нет активных опросов';
$lang['POLL_DELETED'] = 'Опрос удален и все результаты сброшены';