コード例 #1
0
ファイル: Functions.php プロジェクト: jbroadway/polls
function polls_list_all()
{
    $res = polls\Poll::query('id, title')->order('title asc')->fetch_assoc('id', 'title');
    $out = array();
    $out[] = (object) array('key' => 'default', 'value' => 'Default');
    if ($res) {
        foreach ($res as $k => $v) {
            $out[] = (object) array('key' => $k, 'value' => $v);
        }
    }
    return $out;
}
コード例 #2
0
ファイル: edit.php プロジェクト: jbroadway/polls
<?php

/**
 * The poll builder.
 */
$page->layout = 'admin';
$this->require_acl('admin', 'polls');
$f = new Form('post', $this);
$p = new polls\Poll($this->params[0]);
if ($p->error) {
    $page->title = __('An Error Occurred');
    echo '<p>' . __('The requested poll could not be found.') . '</p>';
    echo '<p>' . $p->error . '</p>';
    return;
}
if (!$f->submit()) {
    $page->title = __('Poll Builder');
    $o = (object) $p->data;
    $o->options = $p->options;
    $page->add_script('/apps/polls/js/poll.edit.js', 'head');
    echo View::render('polls/edit', $o);
} else {
    $p->title = $_POST['title'];
    $p->question = $_POST['question'];
    $p->edited = gmdate('Y-m-d H:i:s');
    $p->editor = User::$user->id;
    $p->votable = isset($_POST['votable']) ? 1 : 0;
    $p->visible = isset($_POST['visible']) ? 1 : 0;
    $p->fallback = isset($_POST['fallback']) ? 1 : 0;
    $p->options = isset($_POST['options']) ? array_filter(explode("\n", str_replace("\r", '', $_POST['options']))) : $p->options;
    $p->allowed = $_POST['allowed'] ? $_POST['allowed'] : 1;
コード例 #3
0
ファイル: admin.php プロジェクト: jbroadway/polls
<?php

$this->require_acl('admin', 'polls');
$page->layout = 'admin';
$page->title = __('Polls');
require_once 'apps/polls/lib/Functions.php';
$limit = 15;
$num = is_numeric($_GET['page']) ? $_GET['page'] : 0;
// from the URL, e.g. /myapp/handler/#
$offset = $num * $limit;
$items = polls\Poll::query()->order('edited', 'desc')->fetch($limit, $offset);
$items = $items ? $items : array();
$data = array('limit' => $limit, 'total' => polls\Poll::query()->order('id', 'desc')->count(), 'items' => $items, 'count' => count($items), 'url' => '/polls/admin?page=%d');
// $page->add_style($page->wrap_script('/apps/poll/css/admin.css'));
// $page->add_style($page->wrap_script('/apps/poll/js/admin.js'));
// $page->add_style($page->wrap_script('/apps/poll/css/icons.css'));
echo View::render('polls/admin', $data);
コード例 #4
0
ファイル: index.php プロジェクト: techborn/polls
<?php

if (!$this->internal) {
    $page->window_title = "Polls";
}
$id = isset($this->params[0]) ? $this->params[0] === 'default' ? false : (int) $this->params[0] : (isset($data['id']) ? (int) $data['id'] : 0);
$color = isset($data['override']) && $data['override'] == 1 && isset($data['color']) ? $data['color'] : false;
$async = isset($data['async']) && $data['async'] ? true : false;
$page->add_script('/apps/polls/js/poll.js', 'head');
$page->add_style('/apps/polls/css/poll.css', 'head');
if (!$id) {
    $id = polls\Poll::get_default()->id;
}
$head = false;
if (!$this->internal || $async) {
    $head = View::render('polls/head', array('polls' => polls\Poll::query()->where('visible', true)->order('id', 'desc')->fetch_assoc('id', 'title'), 'active' => $id));
}
echo View::render('polls/index', array('current' => $id, 'color' => $color, 'head' => $head));
コード例 #5
0
ファイル: add.php プロジェクト: techborn/polls
<?php

/**
 * Creates a new untitled form and forwards to /poll/edit, the poll builder.
 */
$this->require_acl('admin', 'polls');
$default = (int) (!(bool) polls\Poll::query()->count());
$p = new polls\Poll(array('title' => 'Untitled', 'question' => 'Please select an option.', 'created' => gmdate('Y-m-d H:i:s'), 'creator' => User::$user->id, 'edited' => gmdate('Y-m-d H:i:s'), 'editor' => User::$user->id, 'fallback' => $default, 'options' => '{}', 'color' => '#0070C0'));
if (!$p->put()) {
    $this->add_notification(__('Unable to create a new poll.'));
    $this->add_notification(__('Error: ' . $p->error));
    @error_log('Error: Poll - ' . $p->error);
    $this->redirect('/polls/admin');
}
\Versions::add($p);
$this->redirect('/polls/edit/' . $p->id);
コード例 #6
0
ファイル: delete.php プロジェクト: techborn/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}'");
        }
    }
}
$this->redirect('/polls/admin');