添加到 trunk
+YUCHENG HU+ git-svn-id: https://svn.code.sf.net/p/hawebs/svn@276 a2543c7e-f6e9-4f8a-8bff-1ffc34733512
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
# @version $Id: components/com_apoll/apoll.php
|
||||
# @package: Apoll Vote
|
||||
# ===================================================
|
||||
# @author
|
||||
# Name: Hristo Genev
|
||||
# Email: [email protected]
|
||||
# Url: http://www.afactory.org
|
||||
# ===================================================
|
||||
# @copyright Copyright (C) 2008 aFactory.org All rights reserved.
|
||||
# @license see http://www.gnu.org/licenses/lgpl.html GNU/LGPL.
|
||||
# You can use, redistribute this file and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as published by
|
||||
# the Free Software Foundation.
|
||||
# License http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL, see LICENSE.php
|
||||
|
||||
// no direct access
|
||||
defined( '_JEXEC' ) or die( 'Restricted access' );
|
||||
|
||||
// Set the table directory
|
||||
JTable::addIncludePath(JPATH_COMPONENT_ADMINISTRATOR.DS.'tables');
|
||||
|
||||
// Require the base controller
|
||||
require_once (JPATH_COMPONENT.DS.'controller.php');
|
||||
|
||||
// Require specific controller if requested
|
||||
if($controller = JRequest::getWord('c')) {
|
||||
$path = JPATH_COMPONENT.DS.'controllers'.DS.$controller.'.php';
|
||||
if (file_exists($path)) {
|
||||
require_once $path;
|
||||
} else {
|
||||
$controller = '';
|
||||
}
|
||||
}
|
||||
|
||||
// Create the controller
|
||||
$classname = 'ApollController'.ucfirst($controller);
|
||||
$controller = new $classname( );
|
||||
|
||||
// Register Extra tasks
|
||||
$controller->registerTask( 'results', 'display' );
|
||||
|
||||
// Perform the Request task
|
||||
$controller->execute(JRequest::getCmd('task'));
|
||||
|
||||
// Redirect if set by the controller
|
||||
$controller->redirect();
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
# @file: controller.php
|
||||
# @package: aPoll
|
||||
# ===================================================
|
||||
# @author
|
||||
# Name: Hristo Genev
|
||||
# Email: [email protected]
|
||||
# Url: http://www.afactory.org
|
||||
# ===================================================
|
||||
# @copyright Copyright (C) 2008 aFactory.org All rights reserved.
|
||||
# @license see http://www.gnu.org/licenses/lgpl.html GNU/LGPL.
|
||||
# You can use, redistribute this file and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as published by
|
||||
# the Free Software Foundation.
|
||||
# License http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL, see LICENSE.php
|
||||
|
||||
// no direct access
|
||||
defined( '_JEXEC' ) or die( 'Restricted access' );
|
||||
|
||||
jimport('joomla.application.component.controller');
|
||||
|
||||
/**
|
||||
* Static class to hold controller functions for the Poll component
|
||||
*
|
||||
* @static
|
||||
* @author Johan Janssens <[email protected]>
|
||||
* @package Joomla
|
||||
* @subpackage Poll
|
||||
* @since 1.5
|
||||
*/
|
||||
class ApollController extends JController
|
||||
{
|
||||
function display()
|
||||
{
|
||||
|
||||
//Set the default view, just in case
|
||||
$view = JRequest::getCmd('view');
|
||||
if(empty($view)) {
|
||||
JRequest::setVar('view', 'apolls');
|
||||
};
|
||||
parent::display();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a vote to an option
|
||||
*/
|
||||
function vote()
|
||||
{
|
||||
global $mainframe;
|
||||
|
||||
// Check for request forgeries
|
||||
JRequest::checkToken() or jexit( 'Invalid Token' );
|
||||
|
||||
$db =& JFactory::getDBO();
|
||||
$apoll_id = JRequest::getVar( 'id', 0, '', 'int' );
|
||||
$option_id = JRequest::getVar( 'voteid', 0, 'post', 'int' );
|
||||
$apoll =& JTable::getInstance('apoll','Table');
|
||||
if (!$apoll->load( $apoll_id ) || $apoll->published != 1) {
|
||||
JError::raiseWarning( 404, JText::_('ALERTNOTAUTH') );
|
||||
return;
|
||||
}
|
||||
|
||||
$cookieName = JUtility::getHash( $mainframe->getName() . 'apoll' . $apoll_id );
|
||||
$voted = JRequest::getVar( $cookieName, '0', 'COOKIE', 'INT');
|
||||
|
||||
if ($voted || !$option_id )
|
||||
{
|
||||
if($voted) {
|
||||
$msg = JText::_('You already voted for this poll!');
|
||||
$tom = "error";
|
||||
}
|
||||
|
||||
if(!$option_id){
|
||||
$msg = JText::_('WARNSELECT');
|
||||
$tom = "error";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
require_once(JPATH_COMPONENT.DS.'models'.DS.'apoll.php');
|
||||
$model = new ApollModelApoll();
|
||||
if ( $model->vote( $apoll_id, $option_id )) {
|
||||
//Set cookie showing that user has voted
|
||||
setcookie( $cookieName, '1', time() + 60*$apoll->lag );
|
||||
}
|
||||
|
||||
$msg = JText::_( 'Thanks for your vote!' );
|
||||
$tom = "";
|
||||
}
|
||||
|
||||
// set Itemid id for links
|
||||
$menu = &JSite::getMenu();
|
||||
$items = $menu->getItems('link', 'index.php?option=com_apoll&view=apoll');
|
||||
|
||||
$itemid = isset($items[0]) ? '&Itemid='.$items[0]->id : '';
|
||||
|
||||
$this->setRedirect( JRoute::_('index.php?option=com_apoll&view=apoll&id='. $apoll_id.':'.$apoll->alias.$itemid, false), $msg, $tom);
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1 @@
|
||||
<html><body bgcolor="#FFFFFF"></body></html>
|
||||
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
# @file components/com_apoll/models/ajaxvote.php
|
||||
# @package: aPoll
|
||||
# ===================================================
|
||||
# @author
|
||||
# Name: Hristo Genev
|
||||
# Email: [email protected]
|
||||
# Url: http://www.afactory.org
|
||||
# ===================================================
|
||||
# @copyright Copyright (C) 2008 aFactory.org All rights reserved.
|
||||
# @license see http://www.gnu.org/licenses/lgpl.html GNU/LGPL.
|
||||
# You can use, redistribute this file and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as published by
|
||||
# the Free Software Foundation.
|
||||
# License http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL, see LICENSE.php
|
||||
|
||||
// Check to ensure this file is included in Joomla!
|
||||
defined('_JEXEC') or die( 'Restricted access' );
|
||||
|
||||
jimport( 'joomla.application.component.model' );
|
||||
|
||||
/**
|
||||
* @package Joomla
|
||||
* @subpackage Apolls
|
||||
*/
|
||||
class ApollModelAjaxvote extends JModel
|
||||
{
|
||||
var $_data = null;
|
||||
var $_total = null;
|
||||
var $_voted = null;
|
||||
|
||||
function getVoted()
|
||||
{
|
||||
global $mainframe;
|
||||
|
||||
// Check for request forgeries
|
||||
JRequest::checkToken() or jexit( 'Invalid Token' );
|
||||
|
||||
$apoll_id = JRequest::getVar( 'id', 0, 'POST', 'int' );
|
||||
$option_id = JRequest::getVar( 'voteid', 0, 'POST', 'int' );
|
||||
$apoll =& JTable::getInstance('apoll','Table');
|
||||
if (!$apoll->load( $apoll_id ) || $apoll->published != 1) {
|
||||
JError::raiseWarning( 404, JText::_('ALERTNOTAUTH') );
|
||||
return;
|
||||
}
|
||||
|
||||
$cookieName = JUtility::getHash( $mainframe->getName() . 'apoll' . $apoll_id );
|
||||
$voted = JRequest::getVar( $cookieName, '0', 'COOKIE', 'INT');
|
||||
|
||||
if ($voted || !$option_id )
|
||||
{
|
||||
if($voted) {
|
||||
$msg = JText::_('You already voted for this poll!');
|
||||
$tom = "error";
|
||||
}
|
||||
if(!$option_id){
|
||||
$msg = JText::_('WARNSELECT');
|
||||
$tom = "error";
|
||||
}
|
||||
$this->_voted = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
require_once(JPATH_COMPONENT.DS.'models'.DS.'apoll.php');
|
||||
$model = new ApollModelApoll();
|
||||
if($model->vote( $apoll_id, $option_id )) {
|
||||
$this->_voted = 1;
|
||||
//Set cookie showing that user has voted
|
||||
setcookie( $cookieName, '1', time() + 60*$apoll->lag );
|
||||
} else {
|
||||
$this->_voted = 0;
|
||||
}
|
||||
}
|
||||
return $this->_voted = 1;
|
||||
}
|
||||
|
||||
function getData()
|
||||
{
|
||||
// Lets load the content if it doesn't already exist
|
||||
if (empty($this->_data))
|
||||
{
|
||||
$query = $this->_buildQuery();
|
||||
$this->_data = $this->_getList($query);
|
||||
}
|
||||
return $this->_data;
|
||||
}
|
||||
|
||||
function getTotal()
|
||||
{
|
||||
if (empty($this->_total))
|
||||
{
|
||||
$db =& JFactory::getDBO();
|
||||
$query = $this->_buildQuery();
|
||||
$this->_total = $this->_getListCount($query);
|
||||
}
|
||||
return $this->_total;
|
||||
}
|
||||
|
||||
function _buildQuery()
|
||||
{
|
||||
$db =& JFactory::getDBO();
|
||||
$apoll_id = JRequest::getVar( 'id', 0, 'POST', 'int' );
|
||||
$query = "SELECT o.id, o.text, o.color, COUNT(v.id) AS votes"
|
||||
." FROM ".$db->nameQuote('#__apoll_options')." AS o "
|
||||
." LEFT JOIN ".$db->nameQuote('#__apoll_votes')." AS v "
|
||||
." ON o.id = v.option_id "
|
||||
." WHERE o.apoll_id=".(int)$apoll_id
|
||||
." GROUP BY o.id "
|
||||
;
|
||||
return $query;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
# @version $Id: components/com_apoll/models/apoll.php
|
||||
# @package: Apoll Vote
|
||||
# ===================================================
|
||||
# @author
|
||||
# Name: Hristo Genev
|
||||
# Email: [email protected]
|
||||
# Url: http://www.afactory.org
|
||||
# ===================================================
|
||||
# @copyright Copyright (C) 2008 aFactory.org All rights reserved.
|
||||
# @license see http://www.gnu.org/licenses/lgpl.html GNU/LGPL.
|
||||
# You can use, redistribute this file and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as published by
|
||||
# the Free Software Foundation.
|
||||
# License http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL, see LICENSE.php
|
||||
|
||||
// Check to ensure this file is included in Joomla!
|
||||
defined('_JEXEC') or die( 'Restricted access' );
|
||||
|
||||
jimport( 'joomla.application.component.model' );
|
||||
|
||||
/**
|
||||
* @package Joomla
|
||||
* @subpackage Polls
|
||||
*/
|
||||
class ApollModelApoll extends JModel
|
||||
{
|
||||
/**
|
||||
* Add vote
|
||||
* @param int The id of the poll
|
||||
* @param int The id of the option selected
|
||||
*/
|
||||
function vote( $apoll_id, $option_id )
|
||||
{
|
||||
global $mainframe;
|
||||
$db = $this->getDBO();
|
||||
$apoll_id = (int) $apoll_id;
|
||||
$option_id = (int) $option_id;
|
||||
|
||||
$date = &JFactory::getDate();
|
||||
$date->setOffset($mainframe->getCfg('offset'));
|
||||
$ip = $_SERVER['REMOTE_ADDR'];
|
||||
$user =& JFactory::getUser();
|
||||
|
||||
$query = "INSERT INTO ".$db->nameQuote('#__apoll_votes')."
|
||||
SET date = ".$db->Quote($date->toFormat()).",
|
||||
option_id = ".(int) $option_id.",
|
||||
apoll_id = ".(int) $apoll_id.",
|
||||
ip = INET_ATON('".$ip."')".",
|
||||
user_id =".$user->id;
|
||||
|
||||
//Save the vote to the database
|
||||
$db->setQuery( $query );
|
||||
if(!$db->query()) {
|
||||
$msg = $db->stderr();
|
||||
$tom = "error";
|
||||
}
|
||||
return true;
|
||||
}
|
||||
function getOptions() {
|
||||
$db = $this->getDBO();
|
||||
$apoll_id = JRequest::getInt('id', 0);
|
||||
|
||||
$query = "SELECT o.*, COUNT(v.id) AS hits,
|
||||
(SELECT COUNT(id) FROM ".$db->nameQuote('#__apoll_votes')." WHERE apoll_id=".$apoll_id.") AS voters"
|
||||
." FROM ".$db->nameQuote('#__apoll_options')." AS o"
|
||||
." LEFT JOIN ".$db->nameQuote('#__apoll_votes')." AS v"
|
||||
." ON (o.id = v.option_id AND v.apoll_id = " . $apoll_id . ")"
|
||||
." WHERE o.apoll_id = ". $apoll_id
|
||||
." AND o.text <> ''"
|
||||
." GROUP BY o.id "
|
||||
." ORDER BY o.ordering "
|
||||
;
|
||||
|
||||
$db->setQuery( $query );
|
||||
if($votes = $db->loadObjectList()) {
|
||||
return $votes;
|
||||
} else {
|
||||
return $db->stderr();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function getApolls() {
|
||||
$db = $this->getDBO();
|
||||
|
||||
$query = "SELECT id, title, CASE WHEN CHAR_LENGTH(alias) THEN CONCAT_WS(':', id, alias) ELSE id END AS slug
|
||||
FROM ".$db->nameQuote('#__apoll_polls')."
|
||||
WHERE published = 1
|
||||
ORDER BY id";
|
||||
|
||||
$db->setQuery( $query );
|
||||
|
||||
if($pList = $db->loadObjectList()) {
|
||||
return $pList;
|
||||
} else {
|
||||
return $db->stderr();
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,177 @@
|
||||
<?php
|
||||
# @version $Id: components/com_apoll/models/apolls.php
|
||||
# @package: Apoll Vote
|
||||
# ===================================================
|
||||
# @author
|
||||
# Name: Hristo Genev
|
||||
# Email: [email protected]
|
||||
# Url: http://www.afactory.org
|
||||
# ===================================================
|
||||
# @copyright Copyright (C) 2008 aFactory.org All rights reserved.
|
||||
# @license see http://www.gnu.org/licenses/lgpl.html GNU/LGPL.
|
||||
# You can use, redistribute this file and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as published by
|
||||
# the Free Software Foundation.
|
||||
# License http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL, see LICENSE.php
|
||||
|
||||
// Check to ensure this file is included in Joomla!
|
||||
defined('_JEXEC') or die( 'Restricted access' );
|
||||
|
||||
jimport( 'joomla.application.component.model' );
|
||||
|
||||
/**
|
||||
* @package Joomla
|
||||
* @subpackage Polls
|
||||
*/
|
||||
class ApollModelApolls extends JModel
|
||||
{
|
||||
/**
|
||||
* Category ata array
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
var $_data = null;
|
||||
|
||||
/**
|
||||
* Category total
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
var $_total = null;
|
||||
|
||||
/**
|
||||
* Pagination object
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
|
||||
var $_pagination = null;
|
||||
|
||||
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
global $mainframe, $option;
|
||||
|
||||
// Get the pagination request variables
|
||||
$config = JFactory::getConfig();
|
||||
|
||||
// Get the pagination request variables
|
||||
$this->setState('limit', $mainframe->getUserStateFromRequest('com_apoll.limit', 'limit', $config->getValue('config.list_limit'), 'int'));
|
||||
$this->setState('limitstart', JRequest::getVar('limitstart', 0, '', 'int'));
|
||||
|
||||
// In case limit has been changed, adjust limitstart accordingly
|
||||
$this->setState('limitstart', ($this->getState('limit') != 0 ? (floor($this->getState('limitstart') / $this->getState('limit')) * $this->getState('limit')) : 0));
|
||||
|
||||
// Get the filter request variables
|
||||
$this->setState('filter_order', JRequest::getCmd('filter_order', 'ordering'));
|
||||
$this->setState('filter_order_dir', JRequest::getCmd('filter_order_Dir', 'ASC'));
|
||||
|
||||
}
|
||||
/**
|
||||
* Method to get poll item data
|
||||
*
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
function getData()
|
||||
{
|
||||
// Lets load the content if it doesn't already exist
|
||||
if (empty($this->_data))
|
||||
{
|
||||
$query = $this->_buildQuery();
|
||||
$this->_data = $this->_getList($query, $this->getState('limitstart'), $this->getState('limit'));
|
||||
}
|
||||
|
||||
return $this->_data;
|
||||
}
|
||||
/**
|
||||
* Method to get the total number of weblink items
|
||||
*
|
||||
* @access public
|
||||
* @return integer
|
||||
*/
|
||||
function getTotal()
|
||||
{
|
||||
// Lets load the content if it doesn't already exist
|
||||
if (empty($this->_total))
|
||||
{
|
||||
$query = $this->_buildQuery();
|
||||
$this->_total = $this->_getListCount($query);
|
||||
}
|
||||
|
||||
return $this->_total;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get a pagination object for the weblinks
|
||||
*
|
||||
* @access public
|
||||
* @return integer
|
||||
*/
|
||||
function getPagination()
|
||||
{
|
||||
// Lets load the content if it doesn't already exist
|
||||
if (empty($this->_pagination))
|
||||
{
|
||||
jimport('joomla.html.pagination');
|
||||
$this->_pagination = new JPagination( $this->getTotal(), $this->getState('limitstart'), $this->getState('limit') );
|
||||
}
|
||||
|
||||
return $this->_pagination;
|
||||
}
|
||||
function _buildQuery()
|
||||
{
|
||||
$where = $this->_buildContentWhere();
|
||||
$orderby = $this->_buildContentOrderBy();
|
||||
$db =& JFactory::getDBO();
|
||||
$query = "SELECT m.*,
|
||||
CASE WHEN CHAR_LENGTH(m.alias) THEN CONCAT_WS(':', m.id, m.alias) ELSE m.id END as slug,
|
||||
CASE WHEN publish_down>NOW() THEN 'active' ELSE 'ended' END AS status,"
|
||||
. " (SELECT COUNT(v.id) FROM ".$db->nameQuote('#__apoll_votes')." AS v WHERE v.apoll_id = m.id) AS voters," . " COUNT(o.id) AS numoptions "
|
||||
. " FROM ".$db->nameQuote('#__apoll_polls') ." AS m "
|
||||
. " LEFT JOIN ".$db->nameQuote('#__apoll_options')." AS o "
|
||||
. " ON o.apoll_id = m.id "
|
||||
. " WHERE m.published=1 AND o.text <> ''"
|
||||
. $where
|
||||
. " GROUP BY m.id"
|
||||
. $orderby
|
||||
;
|
||||
|
||||
return $query;
|
||||
}
|
||||
function _buildContentOrderBy()
|
||||
{
|
||||
global $mainframe, $option;
|
||||
|
||||
$filter_order = $mainframe->getUserStateFromRequest( "$option.filter_order.apolls", 'filter_order', 'm.id', 'cmd' );
|
||||
$filter_order_Dir = $mainframe->getUserStateFromRequest( "$option.filter_order_Dir.apolls", 'filter_order_Dir', '', 'word' );
|
||||
|
||||
$orderby = ' ORDER BY '. $filter_order .' '. $filter_order_Dir;
|
||||
|
||||
return $orderby;
|
||||
}
|
||||
|
||||
function _buildContentWhere()
|
||||
{
|
||||
global $mainframe, $option;
|
||||
$db =& JFactory::getDBO();
|
||||
$filter_order = $mainframe->getUserStateFromRequest( "$option.filter_order.apolls", 'filter_order', 'm.id', 'cmd' );
|
||||
$filter_order_Dir = $mainframe->getUserStateFromRequest( "$option.filter_order_Dir.apolls", 'filter_order_Dir', '', 'word' );
|
||||
$search = $mainframe->getUserStateFromRequest( "$option.search.apolls",'search','','string');
|
||||
|
||||
$where = array();
|
||||
|
||||
if ($search)
|
||||
{
|
||||
$search = JString::strtolower( $search );
|
||||
$where[] = 'LOWER(m.title) LIKE '.$db->Quote( '%'.$db->getEscaped( $search, true ).'%', false );
|
||||
}
|
||||
|
||||
$where = ( count( $where ) ? ' AND '. implode( ' AND ', $where ) : '' );
|
||||
|
||||
return $where;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1 @@
|
||||
<html><body bgcolor="#FFFFFF"></body></html>
|
||||
@@ -0,0 +1,148 @@
|
||||
<?php
|
||||
# @version $Id: components/com_apoll/router.php 02.11.09 14:34
|
||||
# @package: Apoll Vote
|
||||
# ===================================================
|
||||
# @author
|
||||
# Name: Hristo Genev
|
||||
# Email: [email protected]
|
||||
# Url: http://www.afactory.org
|
||||
# ===================================================
|
||||
# @copyright Copyright (C) 2008 aFactory.org All rights reserved.
|
||||
# @license see http://www.gnu.org/licenses/lgpl.html GNU/LGPL.
|
||||
# You can use, redistribute this file and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as published by
|
||||
# the Free Software Foundation.
|
||||
# License http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL, see LICENSE.php
|
||||
|
||||
/**
|
||||
* @param array
|
||||
* @return array
|
||||
*/
|
||||
function ApollBuildRoute( &$query )
|
||||
{
|
||||
static $items;
|
||||
|
||||
$segments = array();
|
||||
$itemid = null;
|
||||
|
||||
// Break up the poll id into numeric and alias values.
|
||||
if (isset($query['id']) && strpos($query['id'], ':')) {
|
||||
list($query['id'], $query['alias']) = explode(':', $query['id'], 2);
|
||||
}
|
||||
|
||||
// Get the menu items for this component.
|
||||
if (!$items) {
|
||||
$component = &JComponentHelper::getComponent('com_apoll');
|
||||
$menu = &JSite::getMenu();
|
||||
$items = $menu->getItems('componentid', $component->id);
|
||||
}
|
||||
|
||||
// Search for an appropriate menu item.
|
||||
// First we will search for menu item linking to this poll,
|
||||
// if we can't find we will look for a menu item linking to the apolls view.
|
||||
|
||||
if (is_array($items))
|
||||
{
|
||||
// If only the option and itemid are specified in the query, return that item.
|
||||
if (!isset($query['view']) && !isset($query['id']) && isset($query['Itemid'])) {
|
||||
$itemid = (int) $query['Itemid'];
|
||||
}
|
||||
|
||||
// Search for a menu that links to the same view and id
|
||||
if (!$itemid) {
|
||||
foreach ($items as $item)
|
||||
{
|
||||
// Check if this menu item links to this view.
|
||||
// menu-view must be equal to the query-view
|
||||
// also menu-id must be equal to the query-id
|
||||
if (isset($item->query['view']) && isset($query['view'])
|
||||
&& $item->query['view'] == $query['view']
|
||||
&& isset($item->query['id'])
|
||||
&& $item->query['id'] == $query['id'])
|
||||
{
|
||||
$itemid = $item->id;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If no specific link has been found, search for a general one.
|
||||
// Search for a menu linking to apolls view
|
||||
if (!$itemid) {
|
||||
foreach ($items as $item)
|
||||
{
|
||||
if (isset($query['view']) && $query['view'] == 'apoll' && isset($item->query['view']) && $item->query['view'] == 'apolls')
|
||||
{
|
||||
// Check for an undealt with poll id.
|
||||
if (isset($query['id']))
|
||||
{
|
||||
// This menu item links to the apolls view but we need to append the poll id to it.
|
||||
$itemid = $item->id;
|
||||
$segments[] = isset($query['alias']) ? $query['id'].':'.$query['alias'] : $query['id'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check if the router found an appropriate itemid.
|
||||
if (!$itemid)
|
||||
{
|
||||
//if item id was not found that means that there is no link to either apolls view or apoll view
|
||||
// Check if a id was specified.
|
||||
if (isset($query['id']))
|
||||
{
|
||||
if (isset($query['alias'])) {
|
||||
$query['id'] .= ':'.$query['alias'];
|
||||
}
|
||||
|
||||
// Push the id onto the stack.
|
||||
$segments[] = 'apoll';
|
||||
$segments[] = $query['id'];
|
||||
|
||||
unset($query['id']);
|
||||
unset($query['alias']);
|
||||
}
|
||||
unset($query['view']);
|
||||
}
|
||||
else
|
||||
{
|
||||
$query['Itemid'] = $itemid;
|
||||
|
||||
// Remove the unnecessary URL segments.
|
||||
unset($query['view']);
|
||||
unset($query['id']);
|
||||
unset($query['alias']);
|
||||
}
|
||||
//print_r($segments); exit;
|
||||
return $segments;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array
|
||||
* @return array
|
||||
*/
|
||||
function ApollParseRoute( $segments )
|
||||
{
|
||||
$vars = array();
|
||||
|
||||
//Get the active menu item if there is a menu link to apolls view
|
||||
$menu =& JSite::getMenu();
|
||||
$item =& $menu->getActive();
|
||||
// Count route segments
|
||||
$count = count( $segments );
|
||||
|
||||
//if item is not set, there is no menu linking to this view - apoll
|
||||
if(!isset($item))
|
||||
{
|
||||
$vars['view'] = 'apoll';
|
||||
$vars['id'] = $segments[$count - 1];
|
||||
return $vars;
|
||||
}
|
||||
//if there is a menu to apolls view ->
|
||||
$vars['view'] = 'apoll';
|
||||
$vars['id'] = $segments[$count-1];
|
||||
|
||||
return $vars;
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
<html><body bgcolor="#FFFFFF"></body></html>
|
||||
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<metadata>
|
||||
<view title="Apoll">
|
||||
<message><![CDATA[TYPEPOLLDESC]]></message>
|
||||
</view>
|
||||
<params>
|
||||
|
||||
</params>
|
||||
</metadata>
|
||||
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
# @file: components/com_apoll/views/apoll/tmpl/default.php
|
||||
# @package: aPoll
|
||||
# ===================================================
|
||||
# @author
|
||||
# Name: Hristo Genev
|
||||
# Email: [email protected]
|
||||
# Url: http://www.afactory.org
|
||||
# ===================================================
|
||||
# @copyright Copyright (C) 2008 aFactory.org All rights reserved.
|
||||
# @license see http://www.gnu.org/licenses/lgpl.html GNU/LGPL.
|
||||
# You can use, redistribute this file and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as published by
|
||||
# the Free Software Foundation.
|
||||
# License http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL, see LICENSE.php
|
||||
|
||||
// no direct access
|
||||
defined('_JEXEC') or die('Restricted access'); ?>
|
||||
|
||||
|
||||
<?php if ($this->params->get( 'show_title', 1)) : ?>
|
||||
<div class="componentheading<?php echo $this->params->get( 'pageclass_sfx' ) ?>">
|
||||
<?php echo $this->escape($this->params->get('page_title')); ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="contentpane<?php echo $this->params->get( 'pageclass_sfx' ) ?>">
|
||||
|
||||
<?php if ($this->allowToVote) : ?>
|
||||
<div id="apoll_comp_form">
|
||||
<form action="<?php echo JRoute::_( 'index.php' );?>" method="post" name="apoll_form2">
|
||||
<?php $k=0; $i=0; $tabcnt = 0;
|
||||
$tabclass = array ('sectiontableentry2', 'sectiontableentry1');
|
||||
foreach($this->options as $option) : ?>
|
||||
<label for="voteid<?php echo $option->id;?>" class="apoll<?php echo $tabclass[$tabcnt]; ?>" style="display:block; padding:2px;">
|
||||
<input type="radio" name="voteid" id="voteid<?php echo $option->id;?>" value="<?php echo $option->id;?>" alt="<?php echo $option->id;?>" />
|
||||
<?php echo $option->text; ?>
|
||||
</label>
|
||||
<?php $tabcnt = 1 - $tabcnt;
|
||||
endforeach;
|
||||
|
||||
$itemid = isset($items[0]) ? '&Itemid='.$items[0]->id : ''; ?>
|
||||
|
||||
<div style="padding:2px; text-align:left;">
|
||||
<input type="submit" name="task_button" class="button" value="<?php echo JText::_('Vote'); ?>" />
|
||||
</div>
|
||||
|
||||
|
||||
<input type="hidden" name="option" value="com_apoll" />
|
||||
<input type="hidden" name="task" value="vote" />
|
||||
<input type="hidden" name="id" value="<?php echo $this->apoll->id;?>" />
|
||||
<?php echo JHTML::_( 'form.token' ); ?>
|
||||
</form>
|
||||
</div>
|
||||
<br />
|
||||
|
||||
<?php
|
||||
//if users are not allowed to vote for some reason (voted or not registered) show warning
|
||||
else :
|
||||
if ($this->params->get('show_component_msg')) :
|
||||
echo "<p>".JText::_($this->msg)."</p>";
|
||||
endif;
|
||||
endif; ?>
|
||||
|
||||
<?php if($this->params->get('show_dropdown')) : ?>
|
||||
<form action="<?php echo JRoute::_( 'index.php' );?>" method="post" name="apoll" id="apoll">
|
||||
<div class="contentpane<?php echo $this->params->get( 'pageclass_sfx' ) ?>">
|
||||
<label for="id">
|
||||
<?php echo JText::_('View results for:'); ?>
|
||||
<?php echo $this->lists['apolls']; ?>
|
||||
</label>
|
||||
</div>
|
||||
</form>
|
||||
<?php endif; ?>
|
||||
<br />
|
||||
<b><?php echo JText::_( 'Statistics' ); ?>:</b>
|
||||
<br />
|
||||
<br />
|
||||
<?php
|
||||
// set the correct view
|
||||
if (!$this->params->get('show_what')) :
|
||||
echo $this->loadTemplate('chart');
|
||||
else :
|
||||
echo $this->loadTemplate('pie');
|
||||
endif;
|
||||
?>
|
||||
<br />
|
||||
<table cellspacing="0" cellpadding="0" border="0">
|
||||
<tbody>
|
||||
<?php if ($this->params->get('show_voters')) : ?>
|
||||
<tr>
|
||||
<td class="smalldark">
|
||||
<?php echo JText::_( 'Number of Voters' ); ?>
|
||||
</td>
|
||||
<td class="smalldark">
|
||||
:
|
||||
<?php if (isset($this->options[0])) echo $this->options[0]->voters; ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($this->params->get('show_times')) : ?>
|
||||
<tr>
|
||||
<td class="smalldark">
|
||||
<?php echo JText::_( 'Start' ); ?>
|
||||
</td>
|
||||
<td class="smalldark">
|
||||
:
|
||||
<?php echo $this->apoll->publish_up; ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="smalldark">
|
||||
<?php echo JText::_( 'End' ); ?>
|
||||
</td>
|
||||
<td class="smalldark">
|
||||
:
|
||||
<?php echo $this->apoll->publish_down; ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endif; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
<br style="clear:both" />
|
||||
</div>
|
||||
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<metadata>
|
||||
<layout title="Single Poll">
|
||||
<message>
|
||||
<![CDATA[STANDARD POLL LAYOUT DESC]]>
|
||||
</message>
|
||||
</layout>
|
||||
<state>
|
||||
<name>Single Poll Layout</name>
|
||||
<description>STANDARD POLL LAYOUT DESC</description>
|
||||
<url addpath="/administrator/components/com_apoll/elements">
|
||||
<param name="id" type="apoll" default="0" label="Apoll" description="A poll" />
|
||||
</url>
|
||||
<params />
|
||||
|
||||
</state>
|
||||
</metadata>
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
# @file: components/com_apoll/views/apoll/tmpl/default_chart.php
|
||||
# @package: aPoll
|
||||
# ===================================================
|
||||
# @author
|
||||
# Name: Hristo Genev
|
||||
# Email: [email protected]
|
||||
# Url: http://www.afactory.org
|
||||
# ===================================================
|
||||
# @copyright Copyright (C) 2008 aFactory.org All rights reserved.
|
||||
# @license see http://www.gnu.org/licenses/lgpl.html GNU/LGPL.
|
||||
# You can use, redistribute this file and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as published by
|
||||
# the Free Software Foundation.
|
||||
# License http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL, see LICENSE.php
|
||||
|
||||
// no direct access
|
||||
defined('_JEXEC') or die('Restricted access'); ?>
|
||||
|
||||
<table class="pollstableborder" cellspacing="0" cellpadding="0" border="0" style="martin-top:10px;">
|
||||
<?php
|
||||
$k=0; $i=0;
|
||||
foreach($this->options as $option) : ?>
|
||||
<tr class="sectiontableentry2">
|
||||
<td width="100%" colspan="2" style="font-size:<?php echo $this->params->get('optionsFontSize'); ?>px;">
|
||||
<?php echo $option->text; ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="sectiontableentry1">
|
||||
<td>
|
||||
<?php if ($this->params->get('show_hits')) { ?>
|
||||
<strong><?php echo JText::_('Votes'); echo ": ".$option->hits; ?></strong>
|
||||
<?php } ?>
|
||||
</td>
|
||||
<td width="<?php echo$this->params->get('chartX'); ?>" >
|
||||
<div style="width:100%; border:<?php echo $this->params->get('bgBarBorder'); ?>; background:#<?php echo$this->params->get('bgBarColor'); ?>; height:<?php echo$this->params->get('barHeight'); ?>px;">
|
||||
<div id="apoll_bar<?php echo $i; ?>" style="height:<?php echo$this->params->get('barHeight')-2; ?>px; width:<?php echo $option->percent; ?>%; float:left; background-color:#<?php echo $option->color ?>; border:<?php echo $this->params->get('barBorder'); ?> "></div><span style="float:left; padding-left:3px;"><?php echo $option->percent; ?>%</span> </div>
|
||||
</td>
|
||||
</tr>
|
||||
<? $k= 1-$k; $i++; ?>
|
||||
<?php endforeach; ?>
|
||||
</table>
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
# @file: components/com_apoll/views/apoll/tmpl/default_pie.php
|
||||
# @package: aPoll
|
||||
# ===================================================
|
||||
# @author
|
||||
# Name: Hristo Genev
|
||||
# Email: [email protected]
|
||||
# Url: http://www.afactory.org
|
||||
# ===================================================
|
||||
# @copyright Copyright (C) 2008 aFactory.org All rights reserved.
|
||||
# @license see http://www.gnu.org/licenses/lgpl.html GNU/LGPL.
|
||||
# You can use, redistribute this file and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as published by
|
||||
# the Free Software Foundation.
|
||||
# License http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL, see LICENSE.php
|
||||
|
||||
// no direct access
|
||||
defined('_JEXEC') or die('Restricted access');
|
||||
|
||||
$document =& JFactory::getDocument();
|
||||
$document->addScriptDeclaration($this->js);
|
||||
$document->addScript(JURI::base().'media/system/js/json.js');
|
||||
?>
|
||||
<div id="my_apoll">
|
||||
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="graph-2" width="<?php echo $this->params->get('pieX'); ?>" height="<?php echo $this->params->get('pieY'); ?>">
|
||||
<param name="wmode" value="transparent" />
|
||||
<param name="movie" value="<?php echo JURI::base().'media/system/swf/open-flash-chart.swf'; ?>" />
|
||||
|
||||
<!--[if !IE]>-->
|
||||
<object type="application/x-shockwave-flash" data="<?php echo JURI::base().'media/system/swf/open-flash-chart.swf'; ?>" name="open-flash-chart" width="<?php echo $this->params->get('pieX'); ?>" height="<?php echo $this->params->get('pieY'); ?>">
|
||||
<!--<![endif]-->
|
||||
|
||||
<p>No Flash Player Installed</p>
|
||||
<!--[if !IE]>-->
|
||||
</object>
|
||||
<!--<![endif]-->
|
||||
</object>
|
||||
</div>
|
||||
@@ -0,0 +1 @@
|
||||
<html><body bgcolor="#FFFFFF"></body></html>
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
# @version $Id: administator/components/com_apoll/views/result/tmpl/default.php
|
||||
# @package: Apoll Vote
|
||||
# ===================================================
|
||||
# @author
|
||||
# Name: Hristo Genev
|
||||
# Email: [email protected]
|
||||
# Url: http://www.afactory.org
|
||||
# ===================================================
|
||||
# @copyright Copyright (C) 2008 aFactory.org All rights reserved.
|
||||
# @license see http://www.gnu.org/licenses/lgpl.html GNU/LGPL.
|
||||
# You can use, redistribute this file and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as published by
|
||||
# the Free Software Foundation.
|
||||
# License http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL, see LICENSE.php
|
||||
|
||||
defined('_JEXEC') or die('Restricted access');
|
||||
|
||||
$document =& JFactory::getDocument();
|
||||
$document->setMimeEncoding('text/xml');
|
||||
|
||||
echo '<?xml version="1.0" encoding="UTF-8" ?>'."\n";
|
||||
echo $this->xml;
|
||||
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<metadata>
|
||||
<layout hidden="true" />
|
||||
</metadata>
|
||||
@@ -0,0 +1,292 @@
|
||||
<?php
|
||||
# @file: components/com_apoll/views/apoll/view.html.php
|
||||
# @package: aPoll
|
||||
# ===================================================
|
||||
# @author
|
||||
# Name: Hristo Genev
|
||||
# Email: [email protected]
|
||||
# Url: http://www.afactory.org
|
||||
# ===================================================
|
||||
# @copyright Copyright (C) 2008 aFactory.org All rights reserved.
|
||||
# @license see http://www.gnu.org/licenses/lgpl.html GNU/LGPL.
|
||||
# You can use, redistribute this file and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as published by
|
||||
# the Free Software Foundation.
|
||||
# License http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL, see LICENSE.php
|
||||
|
||||
// Check to ensure this file is included in Joomla!
|
||||
defined('_JEXEC') or die( 'Restricted access' );
|
||||
|
||||
jimport( 'joomla.application.component.view');
|
||||
|
||||
class ApollViewApoll extends JView
|
||||
{
|
||||
function display($tpl = null)
|
||||
{
|
||||
global $mainframe;
|
||||
|
||||
$db =& JFactory::getDBO();
|
||||
$document =& JFactory::getDocument();
|
||||
$pathway =& $mainframe->getPathway();
|
||||
|
||||
$apoll_id = JRequest::getInt('id', 0);
|
||||
|
||||
$apoll =& JTable::getInstance('apoll', 'Table');
|
||||
$apoll->load( $apoll_id );
|
||||
|
||||
// if id value is passed and apoll not published then exit
|
||||
if ($apoll->id > 0 && $apoll->published != 1) {
|
||||
JError::raiseError( 403, JText::_('Access Forbidden') );
|
||||
return;
|
||||
}
|
||||
|
||||
// Adds parameter handling
|
||||
$params =& $mainframe->getParams();
|
||||
$apollParams = new JParameter($apoll->params);
|
||||
$params->merge($apollParams, $params);
|
||||
|
||||
//Set page title information
|
||||
$menus =& JSite::getMenu();
|
||||
$menu = $menus->getActive();
|
||||
|
||||
// because the application sets a default page title, we need to get it
|
||||
// right from the menu item itself
|
||||
if (is_object( $menu )) {
|
||||
$menu_params = new JParameter( $menu->params );
|
||||
if (!$menu_params->get( 'page_title')) {
|
||||
$params->set('page_title', $apoll->title);
|
||||
}
|
||||
} else {
|
||||
$params->set('page_title', $apoll->title);
|
||||
}
|
||||
$document->setTitle( $params->get( 'page_title' ) );
|
||||
|
||||
//Set pathway information
|
||||
$pathway->addItem($apoll->title, '');
|
||||
|
||||
$params->def( 'show_page_title', 1 );
|
||||
$params->def( 'page_title', $apoll->title );
|
||||
|
||||
|
||||
|
||||
// Check if there is a apoll corresponding to id and if apoll is published
|
||||
if ($apoll->id > 0) {
|
||||
if (empty( $apoll->title )) {
|
||||
$apoll->id = 0;
|
||||
$apoll->title = JText::_( 'Select poll from the list' );
|
||||
}
|
||||
//get the array of options
|
||||
$options =& $this->get('Options');
|
||||
|
||||
} else {
|
||||
$options = array();
|
||||
}
|
||||
|
||||
// list of apolls for dropdown selection
|
||||
$pList = $this->get('Apolls');
|
||||
|
||||
foreach ($pList as $k=>$p) {
|
||||
$pList[$k]->url = JRoute::_('index.php?option=com_apoll&view=apoll&id='.$p->slug);
|
||||
}
|
||||
|
||||
array_unshift( $pList, JHTML::_('select.option', '', JText::_( 'Select Poll from the list' ), 'url', 'title' ));
|
||||
|
||||
// dropdown output
|
||||
$lists = array();
|
||||
|
||||
$lists['apolls'] = JHTML::_('select.genericlist', $pList, 'id',
|
||||
'class="inputbox" size="1" style="width:400px" onchange="if (this.options[selectedIndex].value != \'\') {document.location.href=this.options[selectedIndex].value}"',
|
||||
'url', 'title',
|
||||
JRoute::_('index.php?option=com_apoll&view=apoll&id='.$apoll->id.':'.$apoll->alias)
|
||||
);
|
||||
|
||||
//get the number of voters
|
||||
$voters = isset($options[0]) ? $options[0]->voters : 0;
|
||||
$num_of_options = count( $options );
|
||||
|
||||
for ($i = 0; $i < $num_of_options; $i++) {
|
||||
|
||||
$vote =& $options[$i];
|
||||
//assign pie color to colors array
|
||||
$colors[$i]=$vote->color;
|
||||
//$links[$i]=$vote->link;
|
||||
|
||||
if ($voters > 0) {
|
||||
$vote->percent = round( 100 * $vote->hits / $voters, 1 );
|
||||
} else {
|
||||
//if nobody has voted yet
|
||||
if ($params->get('show_what') == 1) {
|
||||
$vote->percent = round(100/$num_of_options, 1 );
|
||||
} else {
|
||||
$vote->percent = 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// show_what==1 because 1=show pie, 0=joomla default, 3 may be something else later
|
||||
//Pie chart
|
||||
// pass in two arrays, one of data, the other data labels
|
||||
$title_lenght = $params->get('title_lenght');
|
||||
|
||||
|
||||
foreach ($options as $vote_array) {
|
||||
//if show hits is true
|
||||
if($params->get('show_hits')) $hits = " (".$vote_array->hits.")";
|
||||
else $hits = '';
|
||||
//if show options with zero votes is true
|
||||
if ($params->get('show_zero_votes')) {
|
||||
$text = JString::substr(html_entity_decode( $vote_array->text, ENT_QUOTES, "utf-8" ), 0, $title_lenght).$hits;
|
||||
//$values[] = array("value" => $vote_array->percent, "label" => $text, "text" => $text);
|
||||
$values[] = '
|
||||
"value":'.$vote_array->percent.',
|
||||
"label":"'.addslashes($text).'",
|
||||
"text":"'.addslashes($text).'"
|
||||
';
|
||||
|
||||
} else {
|
||||
//show only options that have hits
|
||||
if($vote_array->percent) {
|
||||
$text = JString::substr(html_entity_decode( $vote_array->text, ENT_QUOTES, "utf-8" ), 0, $title_lenght).$hits;
|
||||
//$values[] = array("value" => $vote_array->percent, "label" => $text, "text" => $text);
|
||||
$values[] = '
|
||||
"value":'.$vote_array->percent.',
|
||||
"label":"'.addslashes($text).'",
|
||||
"text":"'.addslashes($text).'"
|
||||
';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// prepare the javascript for the pie
|
||||
//colors and values array to json
|
||||
//TODO use json_encode some day
|
||||
$json_colors = '["'.implode('", "',$colors).'"]';
|
||||
$json_values = '[{'.implode('}, {', $values).'}]';
|
||||
|
||||
$js = '
|
||||
function ofc_ready() {}
|
||||
|
||||
function open_flash_chart_data()
|
||||
{
|
||||
return JSON.stringify(data);
|
||||
}
|
||||
|
||||
var data = {
|
||||
"title":{
|
||||
"text" : "",
|
||||
"style" : "font-size: 14px; font-family: Verdana; text-align: center;"
|
||||
},
|
||||
"bg_colour" : "#'.$params->get("bg_color").'",
|
||||
"elements" :
|
||||
[{
|
||||
"type" : "pie",
|
||||
"tip" : "#label# \n#val#%",
|
||||
"colours" : '.$json_colors.',
|
||||
"alpha" : '.$params->get("opacity").',
|
||||
"start-angle" : '.$params->get("start_angle").',
|
||||
"radius" : '.$params->get("radius").',
|
||||
"no-labels" : '.$params->get("no_labels").',
|
||||
"values" : '. $json_values . ',
|
||||
"gradient-fill" : '.$params->get("gradient"). ',
|
||||
"font-size" : '.$params->get("font_size").',
|
||||
"label-colour" : "#'.$params->get("font_color").'",
|
||||
"animate":[{
|
||||
"distance" : '.$params->get("bounce_dinstance").',
|
||||
"type" : "'.$params->get("animation_type").'"
|
||||
}]
|
||||
}]
|
||||
};
|
||||
';
|
||||
|
||||
//Check if the user has voted
|
||||
$cookieName = JUtility::getHash( $mainframe->getName() . 'apoll' . $apoll_id );
|
||||
$cookieVoted= JRequest::getVar( $cookieName, '0', 'COOKIE', 'INT');
|
||||
$user =& JFactory::getUser();
|
||||
$query = "SELECT date FROM ".$db->nameQuote('#__apoll_votes')
|
||||
." WHERE apoll_id=".(int)$apoll_id
|
||||
." AND user_id=".(int)$user->id
|
||||
;
|
||||
$db->setQuery($query);
|
||||
$userVoted =($db->loadResult())?1:0;
|
||||
$ip = $_SERVER['REMOTE_ADDR'];
|
||||
$query = "SELECT ip FROM ".$db->nameQuote('#__apoll_votes')
|
||||
." WHERE apoll_id=".(int) $apoll_id
|
||||
." AND ip = INET_ATON('".$ip."')";
|
||||
$db->setQuery($query);
|
||||
$ipVoted = ($db->loadResult())?1:0;
|
||||
|
||||
$date = &JFactory::getDate();
|
||||
$date->setOffset($mainframe->getCfg('offset'));
|
||||
$now = $date->toFormat();
|
||||
|
||||
//Algorithm for shoiwing or not the poll in the component
|
||||
if ($params->get('allow_voting')) {
|
||||
if(($now>$apoll->publish_up) && ($now<$apoll->publish_down)) {
|
||||
if ($params->get('only_registered')) {
|
||||
if (!$user->guest) {
|
||||
if($params->get('one_vote_per_user')) {
|
||||
if ($userVoted) {
|
||||
$allowToVote = 0;
|
||||
$msg = "You have already voted";
|
||||
} else {
|
||||
$allowToVote = 1;
|
||||
}
|
||||
} else {
|
||||
if ($cookieVoted) {
|
||||
$allowToVote = 0;
|
||||
$msg = "You have already voted";
|
||||
} else {
|
||||
$allowToVote = 1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$allowToVote = 0;
|
||||
$msg = "Please register to vote";
|
||||
}
|
||||
} else {
|
||||
if ($cookieVoted) {
|
||||
$allowToVote = 0;
|
||||
$msg = "You have already voted";
|
||||
} else {
|
||||
if ($params->get('ip_check')) {
|
||||
if($ipVoted) {
|
||||
$allowToVote = 0;
|
||||
$msg = "You have already voted";
|
||||
} else {
|
||||
$allowToVote = 1;
|
||||
}
|
||||
} else {
|
||||
$allowToVote = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$allowToVote = 0;
|
||||
}
|
||||
|
||||
if($now<$apoll->publish_up) {
|
||||
$msg = "Voting for this poll has not started yet";
|
||||
}
|
||||
if($now>$apoll->publish_down) {
|
||||
$msg = "Voting for this poll has ended.";
|
||||
}
|
||||
} else {
|
||||
$allowToVote = 0;
|
||||
}
|
||||
|
||||
|
||||
$this->assignRef('lists', $lists);
|
||||
$this->assignRef('params', $params);
|
||||
$this->assignRef('apoll', $apoll);
|
||||
$this->assignRef('options', $options);
|
||||
$this->assignRef('allowToVote', $allowToVote);
|
||||
$this->assignRef('msg', $msg);
|
||||
$this->assignRef('js', $js);
|
||||
|
||||
parent::display($tpl);
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
# @file: administator/components/com_apoll/views/apoll/view.raw.php
|
||||
# @package: Apoll Vote
|
||||
# ===================================================
|
||||
# @author
|
||||
# Name: Hristo Genev
|
||||
# Email: [email protected]
|
||||
# Url: http://www.afactory.org
|
||||
# ===================================================
|
||||
# @copyright Copyright (C) 2008 aFactory.org All rights reserved.
|
||||
# @license see http://www.gnu.org/licenses/lgpl.html GNU/LGPL.
|
||||
# You can use, redistribute this file and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as published by
|
||||
# the Free Software Foundation.
|
||||
# License http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL, see LICENSE.php
|
||||
|
||||
// no direct access
|
||||
defined( '_JEXEC' ) or die( 'Restricted access' );
|
||||
|
||||
jimport( 'joomla.application.component.view');
|
||||
|
||||
/**
|
||||
* HTML View class for the Poll component
|
||||
*
|
||||
* @static
|
||||
* @package Joomla
|
||||
* @subpackage aPoll
|
||||
* @since 1.5
|
||||
*/
|
||||
class ApollViewApoll extends JView
|
||||
{
|
||||
function display( $tpl = null )
|
||||
{
|
||||
// Get data from the model
|
||||
require_once(JPATH_COMPONENT.DS.'models'.DS.'ajaxvote.php');
|
||||
$model = new ApollModelAjaxvote();
|
||||
|
||||
$vote = $model->getVoted();
|
||||
$data = $model->getData();
|
||||
$total = $model->getTotal();
|
||||
|
||||
//print_r($data); exit;
|
||||
$apoll_id = JRequest::getVar( 'id', 0, 'POST', 'int' );
|
||||
|
||||
// import library
|
||||
jimport('joomla.utilities.simplexml');
|
||||
// create root node
|
||||
$xml = new JSimpleXMLElement('apoll', array('id' => $apoll_id));
|
||||
// add children
|
||||
|
||||
//get total votes
|
||||
$sum = 0;
|
||||
foreach ($data as $row)
|
||||
{
|
||||
$sum += $row->votes;
|
||||
}
|
||||
|
||||
$number_voters = 0;
|
||||
|
||||
$options =& $xml->addChild('options');
|
||||
|
||||
function toPercent($val, $sum) {
|
||||
return round($val*100/$sum, 1);
|
||||
}
|
||||
for($i=0; $i<$total; $i++)
|
||||
{
|
||||
$option =& $options->addChild('option',
|
||||
array('id'=>$data[$i]->id, 'percentage'=>toPercent($data[$i]->votes, $sum), 'votes'=>$data[$i]->votes, 'color'=>$data[$i]->color));
|
||||
$text =& $option->addChild('text');
|
||||
$text->setData($data[$i]->text);
|
||||
$number_voters += $data[$i]->votes;
|
||||
}
|
||||
$voters =& $xml->addChild('voters');
|
||||
$voters->setData($number_voters);
|
||||
|
||||
$this->assign('xml', $xml->toString());
|
||||
$this->setLayout('raw');
|
||||
parent::display($tpl);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
<html><body bgcolor="#FFFFFF"></body></html>
|
||||
@@ -0,0 +1,148 @@
|
||||
<?php
|
||||
# @file: components/com_apoll/views/apolls/tmpl/default.php
|
||||
# @package: aPoll
|
||||
# ===================================================
|
||||
# @author
|
||||
# Name: Hristo Genev
|
||||
# Email: [email protected]
|
||||
# Url: http://www.afactory.org
|
||||
# ===================================================
|
||||
# @copyright Copyright (C) 2008 aFactory.org All rights reserved.
|
||||
# @license see http://www.gnu.org/licenses/lgpl.html GNU/LGPL.
|
||||
# You can use, redistribute this file and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as published by
|
||||
# the Free Software Foundation.
|
||||
# License http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL, see LICENSE.php
|
||||
|
||||
defined('_JEXEC') or die('Restricted access'); ?>
|
||||
<script language="javascript" type="text/javascript">
|
||||
function tableOrdering( order, dir, task ) {
|
||||
var form = document.adminForm;
|
||||
|
||||
form.filter_order.value = order;
|
||||
form.filter_order_Dir.value = dir;
|
||||
document.adminForm.submit( task );
|
||||
}
|
||||
</script>
|
||||
<?php JHTML::_('behavior.tooltip'); ?>
|
||||
<h1><?php echo $this->params->get('page_title'); ?></h1>
|
||||
<form action="<?php echo JFilterOutput::ampReplace($this->action); ?>" method="post" name="adminForm">
|
||||
<table>
|
||||
<tr>
|
||||
<td align="left" width="100%">
|
||||
<?php if($this->params->get('show_filter_box')) :
|
||||
echo JText::_( 'Filter' ); ?>:
|
||||
<input type="text" name="search" id="search" value="<?php echo $this->lists['search'];?>" class="text_area" onchange="document.adminForm.submit();" />
|
||||
<button onclick="this.form.submit();"><?php echo JText::_( 'Go' ); ?></button>
|
||||
<button onclick="document.getElementById('search').value='';this.form.getElementById('filter_state').value='';this.form.submit();"><?php echo JText::_( 'Reset' ); ?></button>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
<td nowrap="nowrap">
|
||||
<?php
|
||||
echo JText::_('Display Num') .' ';
|
||||
echo $this->pagination->getLimitBox();
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<table width="100%" border="0" cellspacing="0" cellpadding="0">
|
||||
<thead>
|
||||
<tr>
|
||||
<td width="5" height="20" style="" class="sectiontableheader">
|
||||
<?php echo JText::_('Num'); ?>
|
||||
</td>
|
||||
<td class="sectiontableheader">
|
||||
<?php echo JHTML::_('grid.sort','Poll Title', 'm.title', @$this->lists['order_Dir'], @$this->lists['order'] ); ?>
|
||||
</td>
|
||||
<?php if($this->params->get('show_start_date')) { ?>
|
||||
<td width="10%" class="sectiontableheader" style="text-align:center;" nowrap="nowrap">
|
||||
<?php echo JHTML::_('grid.sort','Start', 'm.publish_up', @$this->lists['order_Dir'], @$this->lists['order'] ); ?>
|
||||
</td><?php } ?>
|
||||
<?php if($this->params->get('show_end_date')) { ?>
|
||||
<td width="10%" class="sectiontableheader" style="text-align:center;" nowrap="nowrap">
|
||||
<?php echo JHTML::_('grid.sort','End', 'm.publish_down', @$this->lists['order_Dir'], @$this->lists['order'] ); ?>
|
||||
</td><?php } ?>
|
||||
<?php if($this->params->get('show_status')) { ?>
|
||||
<td width="5%" class="sectiontableheader" style="text-align:center;" nowrap="nowrap">
|
||||
<?php echo JHTML::_('grid.sort','Status', 'status', @$this->lists['order_Dir'], @$this->lists['order'] ); ?>
|
||||
</td><?php } ?>
|
||||
<?php if($this->params->get('show_num_voters')) { ?>
|
||||
<td width="5%" class="sectiontableheader" style="text-align:center;" nowrap="nowrap">
|
||||
<?php echo JHTML::_('grid.sort','Votes', 'voters', @$this->lists['order_Dir'], @$this->lists['order'] ); ?>
|
||||
</td><?php } ?>
|
||||
<?php if($this->params->get('show_num_options')) { ?>
|
||||
<td width="5%" class="sectiontableheader" style="text-align:center;" nowrap="nowrap">
|
||||
<?php echo JHTML::_('grid.sort', 'Options', 'numoptions', @$this->lists['order_Dir'], @$this->lists['order'] ); ?>
|
||||
</td><?php } ?>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
<?php
|
||||
$k = 0;
|
||||
|
||||
for ($i=0, $n=count( $this->items ); $i < $n; $i++)
|
||||
{
|
||||
$row = &$this->items[$i];
|
||||
//find the Itemid that correspondents to the link if any.
|
||||
$component =& JComponentHelper::getComponent('com_apoll');
|
||||
$menus =& JApplication::getMenu('site', array());
|
||||
$menu_items = $menus->getItems('componentid', $component->id);
|
||||
$itemid = null;
|
||||
|
||||
if (isset($menu_items)) {
|
||||
foreach ($menu_items as $item) {
|
||||
if ((@$item->query['view'] == 'apoll') && (@$item->query['id'] == $row->id)) {
|
||||
$itemid = '&Itemid='.$item->id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
$link = JRoute::_( 'index.php?option=com_apoll&view=apoll&id='.$row->slug.$itemid);
|
||||
|
||||
?>
|
||||
<tr class="sectiontableentry<?php echo $k + 1; ?>">
|
||||
<td><?php echo $this->pagination->getRowOffset($i); ?></td>
|
||||
<td><span class="hasTip" title="<?php echo JText::_( 'View Poll' );?>">
|
||||
<a href="<?php echo $link; ?>"><?php echo $row->title; ?></a></span></td>
|
||||
<?php if($this->params->get('show_start_date')) { ?>
|
||||
<td align="center"><?php echo JFactory::getDate($row->publish_up)->toFormat($this->params->get('date_format'))
|
||||
; ?></td>
|
||||
<?php } ?>
|
||||
<?php if($this->params->get('show_end_date')) { ?>
|
||||
<td><?php echo JFactory::getDate($row->publish_down)->toFormat($this->params->get('date_format'))
|
||||
; ?></a></td>
|
||||
<?php } ?>
|
||||
<?php if($this->params->get('show_status')) { ?>
|
||||
<td align="center" style="text-transform:capitalize;">
|
||||
<?php if($this->params->get('show_status_as')) { ?>
|
||||
<img src="<?php echo JURI::base(); ?>media/system/images/apoll-<?php echo $row->status; ?>.gif" />
|
||||
<?php } else {
|
||||
echo JText::_($row->status);
|
||||
} ?></td>
|
||||
<?php
|
||||
}
|
||||
if($this->params->get('show_num_voters')) { ?>
|
||||
<td align="center"><?php echo $row->voters; ?></td>
|
||||
<?php } ?>
|
||||
<?php if($this->params->get('show_num_options')) { ?>
|
||||
<td align="center"><?php echo $row->numoptions; ?></td>
|
||||
<?php } ?>
|
||||
</tr>
|
||||
<?php $k = 1 - $k;
|
||||
} ?>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<div>
|
||||
<?php echo $this->pagination->getPagesLinks(); ?>
|
||||
</div>
|
||||
<div class="pagecounter">
|
||||
<?php echo $this->pagination->getPagesCounter(); ?>
|
||||
</div>
|
||||
|
||||
<input type="hidden" name="filter_order" value="<?php echo $this->lists['order']; ?>" />
|
||||
<input type="hidden" name="filter_order_Dir" value="" />
|
||||
<?php echo JHTML::_( 'form.token' ); ?>
|
||||
</form>
|
||||
<br />
|
||||
@@ -0,0 +1,44 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<metadata>
|
||||
<layout title="List of Polls">
|
||||
<message>
|
||||
<![CDATA[POLLS DESC]]>
|
||||
</message>
|
||||
</layout>
|
||||
<state>
|
||||
|
||||
<params>
|
||||
<param name="show_filter_box" type="radio" default="1" label="SHOW FILTER" description="SHOW FILTER DESC">
|
||||
<option value="1">Yes</option>
|
||||
<option value="0">No</option>
|
||||
</param>
|
||||
<param name="show_status" type="radio" default="1" label="SHOW STATUS" description="SHOW STATUS DESC">
|
||||
<option value="1">Yes</option>
|
||||
<option value="0">No</option>
|
||||
</param>
|
||||
<param name="show_status_as" type="list" default="1" label="SHOW STATUS AS" description="SHOW STATUS AS DESC">
|
||||
<option value="1">Image</option>
|
||||
<option value="0">Text</option>
|
||||
</param>
|
||||
<param name="show_start_date" type="radio" default="1" label="SHOW START DATE" description="SHOW START DATE DESC">
|
||||
<option value="1">Yes</option>
|
||||
<option value="0">No</option>
|
||||
</param>
|
||||
<param name="show_end_date" type="radio" default="1" label="SHOW END DATE" description="SHOW END DATE DESC">
|
||||
<option value="1">Yes</option>
|
||||
<option value="0">No</option>
|
||||
</param>
|
||||
<param name="date_format" type="text" default="%d %b %Y - %H:%M " label="DATE FORMAT" description="DATE FORMAT DESC" size="25" />
|
||||
<param name="show_num_voters" type="radio" default="1" label="SHOW NUM VOTERS" description="SHOW NUM VOTERS DESC">
|
||||
<option value="1">Yes</option>
|
||||
<option value="0">No</option>
|
||||
</param>
|
||||
|
||||
<param name="show_num_options" type="radio" default="1" label="SHOW NUM OPTIONS" description="SHOW NUM VOTERS DESC">
|
||||
<option value="1">Yes</option>
|
||||
<option value="0">No</option>
|
||||
</param>
|
||||
|
||||
</params>
|
||||
</state>
|
||||
</metadata>
|
||||
@@ -0,0 +1 @@
|
||||
<html><body bgcolor="#FFFFFF"></body></html>
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
# @version $Id: components/com_apoll/views/apolls/view.html.php
|
||||
# @package: Apoll Vote
|
||||
# ===================================================
|
||||
# @author
|
||||
# Name: Hristo Genev
|
||||
# Email: [email protected]
|
||||
# Url: http://www.afactory.org
|
||||
# ===================================================
|
||||
# @copyright Copyright (C) 2008 aFactory.org All rights reserved.
|
||||
# @license see http://www.gnu.org/licenses/lgpl.html GNU/LGPL.
|
||||
# You can use, redistribute this file and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as published by
|
||||
# the Free Software Foundation.
|
||||
# License http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL, see LICENSE.php
|
||||
|
||||
// no direct access
|
||||
defined( '_JEXEC' ) or die( 'Restricted access' );
|
||||
|
||||
jimport( 'joomla.application.component.view');
|
||||
|
||||
/**
|
||||
* HTML View class for the Poll component
|
||||
*
|
||||
* @static
|
||||
* @package Joomla
|
||||
* @subpackage Apoll
|
||||
* @since 1.0
|
||||
*/
|
||||
class ApollViewApolls extends JView
|
||||
{
|
||||
function display( $tpl = null )
|
||||
{
|
||||
global $mainframe, $option;
|
||||
|
||||
$db =& JFactory::getDBO();
|
||||
$uri =& JFactory::getURI();
|
||||
$filter_order = $mainframe->getUserStateFromRequest( "$option.filter_order.apolls", 'filter_order', 'm.id', 'cmd' );
|
||||
$filter_order_Dir = $mainframe->getUserStateFromRequest( "$option.filter_order_Dir.apolls", 'filter_order_Dir', '', 'word' );
|
||||
$search = $mainframe->getUserStateFromRequest( "$option.search.apolls",'search','','string');
|
||||
|
||||
// Get data from the model
|
||||
$items =& $this->get( 'Data');
|
||||
$total =& $this->get( 'Total');
|
||||
$pagination =& $this->get( 'Pagination' );
|
||||
// table ordering
|
||||
$lists['order_Dir'] = $filter_order_Dir;
|
||||
$lists['order'] = $filter_order;
|
||||
|
||||
// search filter
|
||||
$lists['search'] = $search;
|
||||
// get menu params
|
||||
$params =& $mainframe->getParams();
|
||||
|
||||
$this->assignRef('lists', $lists);
|
||||
$this->assignRef('items', $items);
|
||||
$this->assignRef('params', $params);
|
||||
$this->assignRef('pagination', $pagination);
|
||||
$this->assignRef('action', $uri->toString());
|
||||
|
||||
parent::display($tpl);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
<html><body bgcolor="#FFFFFF"></body></html>
|
||||
Reference in New Issue
Block a user