Exemplo n.º 1
0
<?php

$this->require_acl('admin', 'polls');
$page->layout = 'admin';
if (!$this->params[0]) {
    $this->redirect('/polls/admin');
}
if (!$this->params[0]) {
    $this->add_notification("Error: Must provide id parameter.");
    isset($_GET['vote']) ? $this->redirect('/polls/votes/') : $this->redirect('/polls/admin');
}
if (isset($_GET['vote']) && User::require_acl('polls/votes')) {
    $item = polls\Votes::get($this->params[0]);
    $user = User::get($item->user_id)->name;
    $poll = $item->poll()->title;
    if (!$item->remove()) {
        @error_log('Error: polls/delete/' . $this->params[0] . '?vote - ' . $item->error);
        $this->add_notification('Error: Unable to delete user\'s vote(s).');
    } else {
        $this->add_notification("Success: Removed vote from '{$poll}' for '{$user}'.");
    }
} else {
    if (User::require_acl('poll')) {
        $item = polls\Poll::get($this->params[0]);
        $old = $item->title;
        if (!$item->remove()) {
            @error_log('Error: polls/delete/' . $this->params[0] . ' - ' . $item->error);
            $this->add_notification('Error: Unable to delete poll.');
        } else {
            $this->add_notification("Success: Removed '{$old}'");
        }
Exemplo n.º 2
0
function polls_votes_count($id)
{
    return polls\Votes::query()->where('poll_id', $id)->count();
}
Exemplo n.º 3
0
<?php

if (!User::require_admin()) {
    $this->redirect('/user/login');
}
if (!User::require_acl('polls')) {
    $this->redirect($_COOKIE['elefant_last_page']);
}
if (!User::require_acl('poll/votes') || !$this->params[0]) {
    $this->redirect('/polls/admin');
}
$page->layout = 'admin';
require_once 'apps/polls/lib/Functions.php';
$limit = 25;
$num = is_numeric($_GET['page']) ? $_GET['page'] : 0;
$offset = $num * $limit;
$items = polls\Votes::query()->where('poll_id', $this->params[0])->order('ts', 'desc')->fetch($limit, $offset);
$data = array('limit' => $limit, 'total' => polls\Votes::query()->where('poll_id', $this->params[0])->count(), 'items' => $items, 'count' => count($items), 'url' => '/polls/votes/' . $this->params[0] . '?page=%d');
$page->add_style('/apps/polls/css/polls.css');
echo View::render('polls/votes', $data);