Опросник на главной

Опросник на главной 1.1.0

Совместимость
не проверялся на совместимость
Изменения в БД
требуются
Автор
_Xz_
Общественное достояние
нет
Описание: добавляет создание опросов для пользователей и гостей сайта на главной странице.
Инструкция по установке
PHP:
-- сделать запросы
- 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 .= '
                        <div align="left">
                            '. $row .'
                            <div class="clear"></div>
                            <div class="floatL">
                                <div class="vote category" style="width: '. $vote_graphic_length .'px;"></div>
                            </div>
                            <div class="floatR med">
                                '. sprintf("%.1d%%", ($vote_percent * 100)) .'&nbsp;['. $users .']
                            </div>
                            <div class="clear"></div>
                        </div>';
                }

                $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']}&amp;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
<!-- IF $bb_cfg['poll_index'] -->
<script type="text/javascript">
$(document).ready(function(){
    $('.RadioClass').change(function(){
        if($(this).is(':checked')){
            $('.RadioSelected:not(:checked)').removeClass('RadioSelected');
            $(this).next('label').addClass('RadioSelected');
            $('#poll_submit').show();
        }
    });
});

function polling(){
    var poll = -1;
    $('input.RadioClass:checked').each(function(){
        poll = this.value;
    });

    $('#poll_option').html('<i class="loading-1">{L_LOADING}</i>');

    if(poll < 0) alert('{L_NO_VOTE_OPTION}');
    else {
        ajax.exec({action : 'poll_index', mode: 'poll', poll: poll});
        <!-- IF IS_GUEST -->
        var ws = new Date();
        ws.setDate(1+ws.getDate());
        document.cookie="poll_index=1; path=/; expires="+ ws.toGMTString();
        <!-- ENDIF -->
    }
}
ajax.callback.poll_index = function(data) {
    $('#poll_option').html(data.html);
}
</script>
<style>
.RadioClass{
    display: none;
}
.RadioLabelClass{
    background: url("/images/poll_index/UnCheck.png") no-repeat;
    padding-left: 30px;
    padding-top: 3px;
    margin: 5px;
    height: 28px;
    width: 70px;
    display: block;
}
.RadioSelected{
    background: url("/images/poll_index/Check.png") no-repeat;
}
.vote {
    border: 1px solid #D6D6D6; height: 7px; border-radius: 4px;
    margin: 3px;
    background-image: linear-gradient(bottom, #D6D6D6 10%, #FFFFFF 51%);
    background-image: -o-linear-gradient(bottom, #D6D6D6 10%, #FFFFFF 51%);
    background-image: -moz-linear-gradient(bottom, #D6D6D6 10%, #FFFFFF 51%);
    background-image: -webkit-linear-gradient(bottom, #D6D6D6 10%, #FFFFFF 51%);
    background-image: -ms-linear-gradient(bottom, #D6D6D6 10%, #FFFFFF 51%);
}
</style>
<a name="poll"></a>
<div align="center" class="category bw_TRBL border">
<h3 class="cat_title tLeft">{L_POLL}</h3>
<!-- IF POLL_ENABLED -->
    <span class="maintitle">{POLL_NAME}</span>
    <div class="clear hr1 mrg_4"></div>

    <div id="poll_option" class="mrg_6">

    <!-- BEGIN poll -->
    <div align="left">
        <input id="{poll.ID}" type="radio" name="poll" class="RadioClass" value="{poll.ID}" >
        <label for="{poll.ID}" class="RadioLabelClass">{poll.OPTION}</label>
    </div>
    <!-- END poll -->

    <!-- BEGIN poll_result -->
    <div align="left">
        {poll_result.OPTION}
        <div class="clear"></div>
        <div class="floatL">
            <div class="vote category" style="width: {poll_result.LENGTH}px;"></div>
        </div>
        <div class="floatR med">
            {poll_result.PERCENT}&nbsp;[{poll_result.USERS}]
        </div>
        <div class="clear"></div>
    </div>
    <!-- END poll_result -->

    <input id="poll_submit" onclick="polling();" type="submit" class="hidden" name="{L_SUBMIT_VOTE}" />

    </div>
<!-- ELSE -->
    <div class="mrg_6 med">{L_NO_POLL}</div>
<!-- ENDIF -->
</div>
<div class="cat_separator"></div>
<!-- ENDIF -->

админка
-- 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
- найти
<tr>
    <td><h4>{L_NEWS_FORUM_ID}</h4></td>
    <td><input class="post" type="text" size="25" maxlength="100" name="network_news_forum_id" value="{NETWORK_NEWS_FORUM_ID}" /></td>
</tr>
- после вставить
<tr class="row3 med">
    <td class="bold tCenter" colspan="2">{L_POLL_ON_INDEX}</td>
</tr>
<tr>
    <td><h4>{L_POLL_ON_INDEX}</h4></td>
    <td>
        <label><input type="radio" name="poll_index" value="1" <!-- IF POLL_ENABLED -->checked="checked"<!-- ENDIF --> />{L_ENABLED}</label>&nbsp;&nbsp;
        <label><input type="radio" name="poll_index" value="0" <!-- IF not POLL_ENABLED -->checked="checked"<!-- ENDIF --> />{L_DISABLED}</label>
    </td>
</tr>
<tr>
    <td><h4>{L_POLL_QUESTION}</h4></td>
    <td>
        <script type="text/javascript">
        function poll_delete(){
            if(!confirm('{L_CONFIRM_DELETE_POLL}')) return false;
            ajax.exec({action : 'poll_index', mode : 'delete'});
            $('#poll_vote').attr('value', '');
            $('#poll_option').remove();
        }
        </script>
        <input id="poll_vote" class="post" type="text" size="50" maxlength="200" name="poll_name" value="{POLL_NAME}" />
        <input onclick="poll_delete();" class="post" type="button" size="2" value="{L_DELETE_POLL}" />
    </td>
</tr>
<tbody id="poll_option">
<!-- BEGIN poll -->
<tr id="poll_{poll.id}">
    <td><h4>{L_ADD_OPTION}</h4><h6></h6></td>
    <td>
        <input class="post" type="text" size="25" maxlength="100" name="poll_vote[]" value="{poll.OPTION}" />
        <input onclick="$('#poll_{poll.ID}').remove();" class="post" type="button" size="2" value="{L_DELETE}" />
    </td>
</tr>
<!-- END poll -->
</tbody>
<tr class="row3 med"><td colspan="2"></td></tr>
<tr id="poll">
    <td><h4>{L_ADD_OPTION}</h4><h6></h6></td>
    <td>
        <input class="post" type="text" size="25" maxlength="100" name="poll_vote[]" value="" />
        <input onclick="$('#poll').clone().appendTo('.poll');" class="post" type="button" size="2" value="+" />
        <input onclick="$('#poll').remove();" class="post" type="button" size="2" value="-" />
    </td>
</tr>
<tbody class="poll"></tbody>
<tr class="row3 med"><td colspan="2"></td></tr>


lang_main.php
// Опрос на главной
$lang['POLL'] = 'Опрос';
$lang['POLL_ON_INDEX'] = 'Опрос на главной';
$lang['NO_POLL'] = 'В данный момент нет активных опросов';
$lang['POLL_DELETED'] = 'Опрос удален и все результаты сброшены';
  • Безымянный.png
    Безымянный.png
    46.5 KB · Просмотры: 576
  • Мне нравится
Реакции: fourdeltaOne, Lange и Lynx
Автор
Exile
Скачивания
123
Просмотры
251
Первый выпуск
Обновление
Оценка
0.00 звёзд 0 оценок

Другие ресурсы пользователя Exile

Последние обновления

  1. Обновление 1.1.0

    Обновлено описание ресурса
Сверху