function poll_on_submit(&$api) { include dirname(__FILE__) . '/poll_controller.class.php'; $controller = new PollController($api); $poll = _poll_get_from_post(); // Add a new option to the poll form. if ($_POST['add_row']) { $option = new PollOption(); if ($poll->n_options() >= $poll->get_max_options()) { $controller->add_hint(new \hint\Hint(_('Too many options.'))); } else { $poll->add_option($option); } return $controller->show_form($poll); } elseif ($_POST['send']) { // Sanity check. $err = $poll->check(); if ($err) { $controller->add_hint(new \hint\Error($err)); return $controller->show_form($poll); } // Save the poll. $poll_id = _save_poll($api, $poll); if (!$poll_id) { $controller->add_hint(new \hint\Error(_('Failed to save poll.'))); return $controller->show_form($poll); } // Refer to the poll. $api->refer_to_posting($poll); } }
<?php /** * @version $Id: poll.php 14401 2010-01-26 14:10:00Z louis $ * @package Joomla * @subpackage Polls * @copyright Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved. * @license GNU/GPL, see LICENSE.php * Joomla! is free software. This version may have been modified pursuant * to the GNU General Public License, and as distributed it includes or * is derivative of works licensed under the GNU General Public License or * other free or open source software licenses. * See COPYRIGHT.php for copyright notices and details. */ // no direct access defined('_JEXEC') or die('Restricted access'); // Make sure the user is authorized to view this page $user =& JFactory::getUser(); if (!$user->authorize('com_poll', 'manage')) { $mainframe->redirect('index.php', JText::_('ALERTNOTAUTH')); } require_once JPATH_COMPONENT . DS . 'controller.php'; // Set the table directory JTable::addIncludePath(JPATH_COMPONENT . DS . 'tables'); // Create the controller $controller = new PollController(); $controller->execute(JRequest::getCmd('task')); $controller->redirect();
PollController::delete($id); }); $routes->get('/poll/:id/delete', function ($id) { PollController::delete($id); }); $routes->post('/poll/adduser/:uid', function ($uid) { PollController::addUser($uid); }); $routes->get('/poll/:id/:uid/removeuser', function ($id, $uid) { PollController::removeUser($id, $uid); }); $routes->get('/poll/:id/:uid/vote', function ($id, $uid) { PollController::vote($id, $uid); }); $routes->post('/poll/:id/:uid/vote', function ($id, $uid) { PollController::saveVote($id, $uid); }); $routes->get('/helloworld', function () { HelloWorldController::index(); }); $routes->get('/hiekkalaatikko', function () { HelloWorldController::sandbox(); }); $routes->get('/poll_list', function () { HelloWorldController::poll_list(); }); $routes->get('/poll_show', function () { HelloWorldController::poll_show(); }); $routes->get('/poll_edit', function () { HelloWorldController::poll_edit();