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; }
$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; $p->required = $_POST['required'] ? $_POST['required'] : 1; if (!$p->put()) { $_POST['options'] = $p->options; $this->add_notification('Error: Unable to save poll data.'); @error_log('Error: ' . $p->error); $page->add_script('/apps/polls/js/poll.edit.js', 'head'); echo View::render('polls/edit', $_POST); return; } if (isset($_POST['fallback'])) { $polls = polls\Poll::query()->where('fallback', true)->fetch(); foreach ($polls as $poll) { if ($poll->id != $this->params[0]) { $poll->fallback = 0; $poll->put(); } } } if (\Versions::recent($p) != $p) { \Versions::add($p); } $this->add_notification('Success.'); $this->redirect('/polls/admin'); }
<?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);
<?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));
<?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);
<?php /** * Creates a new untitled form and forwards to /poll/edit, the poll builder. */ $page->layout = 'admin'; $this->require_acl('admin', 'polls'); $default = !(bool) polls\Poll::query('id')->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)); 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);