Beispiel #1
0
function show_vote($id)
{
    $id = intval($id);
    $data = db_select_one('site_votes', '*', $id);
    if (!$data) {
        return 'Опрос не найден';
    }
    $ans = @unserialize($data['data']);
    # Voting?
    if ($data['is_active'] == 'Y' && user('logged') && isset($_POST['sub_vote']) && !db_select('site_votes_voters', array('id'), '`id`=' . $id . ' AND `uid`=' . user('id'))) {
        # Voting!
        if ($data['type'] == 'S') {
            if (isset($ans[@$_POST['vote_ans']])) {
                $ans[@$_POST['vote_ans']]['a']++;
            }
        } else {
            for ($x = 0; $x < count($ans); $x++) {
                if (in_array($x, @$_POST['vote_ans'])) {
                    $ans[$x]['a']++;
                }
            }
        }
        db_update_by_id('site_votes', $id, array('data' => serialize($ans)));
        db_insert('site_votes_voters', array('id' => $id, 'uid' => user('id'), 'tms' => time()));
        redirect_msg(URL . '/votes/' . $id . '/', 'Спасибо, ваш голос принят!');
        exit;
    }
    # Check - resuilts?
    $out = '';
    $bot = '';
    $is_res = false;
    if ($data['is_active'] != 'Y' || !user('logged') || isset($_GET['vote_resuilts']) || db_select('site_votes_voters', array('id'), '`id`=' . $id . ' AND `uid`=' . user('id'))) {
        $is_res = true;
    }
    $tpl = new ltpl('vote_area');
    $tpl->v('title', $data['title']);
    if ($is_res) {
        $GLOBALS['vote_color'] = 0;
        $all = 0;
        for ($x = 0; $x < count($ans); $x++) {
            $all += $ans[$x]['a'];
        }
        # Show resuilts
        for ($x = 0; $x < count($ans); $x++) {
            $pers = @round($ans[$x]['a'] / $all * 100);
            $out .= '<tr>';
            $out .= '<td width="30" align="center">' . ($x + 1) . '.</td>';
            $out .= '<td align="left">' . htmlspecialchars($ans[$x]['t']) . '</td>';
            #$out .= '<td width="30" align="left">'.intval($ans[$x]['a']).'</td>';
            $out .= '<td width="30" align="left">' . $pers . '%</td>';
            $out .= '</tr>';
            $pers = @round($ans[$x]['a'] / $all * 100);
            if (!$pers) {
                $pers = 1;
            }
            $out .= '<tr>';
            $out .= '<td>&nbsp;</td>';
            $out .= '<td align="left" colspan="2"><table width="100%"><tr><td width="' . $pers . '%" style="background-color:' . vote_color() . ';padding:5px;"><img src="' . URL . '/tpl/images/spacer.gif" alt=""/></td><td><img src="' . URL . '/tpl/images/spacer.gif" alt=""/></td></tr></table></td>';
            $out .= '</tr>';
        }
        if ($data['is_active'] != 'Y') {
            $bot = 'Опрос уже завершен';
        } elseif (!user('logged')) {
            $bot = 'Гости не могут голосовать';
        } elseif (db_select('site_votes_voters', array('id'), '`id`=' . $id . ' AND `uid`=' . user('id'))) {
            $bot = 'Вы уже отдали свой голос';
        } else {
            $bot = '<input type="submit" value="Голосовать"/>';
        }
        #$bot .= '<input type="submit" value="Голосовать"/>';
    } else {
        # Show form
        $idt = mt_rand();
        for ($x = 0; $x < count($ans); $x++) {
            if ($data['type'] == 'S') {
                $ch = '<input type="radio" name="vote_ans" value="' . $x . '" id="vote_' . $idt . '_' . $x . '"/>';
            } else {
                $ch = '<input type="checkbox" name="vote_ans[]" value="' . $x . '" id="vote_' . $idt . '_' . $x . '"/>';
            }
            $out .= '<tr>';
            $out .= '<td width="15" align="center">' . $ch . '</td>';
            $out .= '<td align="left"><label for="vote_' . $idt . '_' . $x . '">' . htmlspecialchars($ans[$x]['t']) . '</label></td>';
            $out .= '</tr>';
        }
        $bot .= '<input type="submit" name="sub_vote" value="Голосовать"/> <input type="button" value="Результаты" onclick="document.location.href=\'' . URL . '/votes/' . $id . '/?vote_resuilts=1\';"/>';
    }
    $tpl->v('id', $id);
    $tpl->v('data', $out);
    $tpl->v('is_res', $is_res);
    $tpl->v('bot', $bot);
    return $tpl->get();
}
Beispiel #2
0
 function del($data)
 {
     ldb_query('DELETE FROM `upload` WHERE `id`=' . $data['id']);
     redirect_msg(URL . '/files/', lang('delete_ok'));
     exit;
 }
Beispiel #3
0
 function logout()
 {
     // Check key
     if (@$_GET['id'] != md5(md5(sha1(@$_COOKIE[cfg('auth_int_cookie_name')])))) {
         return core_error_lng('logout_e_k');
     }
     // Log out?
     ldb_update_by_id('user', user('id'), array('login_key' => '-1', 'last_login' => time(), 'last_ip' => $_SERVER['REMOTE_ADDR']));
     setcookie(cfg('auth_int_cookie_name'), '', time() - 864000, '/', COOKIE_DOMAIN);
     $msg = lang('login_out');
     $msg = str_replace('{NAME}', user('name'), $msg);
     // echo $msg;
     redirect_msg(URL . '/', $msg);
     exit;
 }