添加到 trunk

+YUCHENG HU+

git-svn-id: https://svn.code.sf.net/p/hawebs/svn@328 a2543c7e-f6e9-4f8a-8bff-1ffc34733512
This commit is contained in:
YuCheng Hu
2010-06-13 23:24:07 +00:00
parent 0610a07a16
commit 8250c5fde2
50 changed files with 5141 additions and 0 deletions
@@ -0,0 +1,40 @@
<?php
# @version $Id: administator/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' );
require_once( JPATH_COMPONENT.DS.'controller.php' );
// Set the table directory
JTable::addIncludePath( JPATH_COMPONENT.DS.'tables' );
// 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 = '';
}
}
$classname = 'ApollsController'.ucfirst($controller);
// Create the controller
$controller = new $classname();
$controller->execute( JRequest::getCmd( 'task' ) );
$controller->redirect();
@@ -0,0 +1,105 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<params>
<param type="spacer" default="VOTING FROM COMPONENT" />
<param name="only_registered" type="radio" default="0" label="ONLY REGISTERED" description="ONLY REGISTERED DESC">
<option value="1">Yes</option>
<option value="0">NO</option>
</param>
<param name="one_vote_per_user" type="radio" default="1" label="ONE VOTE PER USER" description="ONE VOTE PER USER DESC">
<option value="1">Yes</option>
<option value="0">NO</option>
</param>
<param name="ip_check" type="radio" default="0" label="ONE VOTE PER IP" description="ONE VOTE PER IP DESC">
<option value="1">Yes</option>
<option value="0">NO</option>
</param>
<param name="show_component_msg" type="radio" default="1" label="SHOW MSG" description="SHOW MSG DESC">
<option value="1">Yes</option>
<option value="0">NO</option>
</param>
<param name="allow_voting" type="radio" default="1" label="ALLOW VOTING" description="ALLOW VOTING DESC">
<option value="1">Yes</option>
<option value="0">NO</option>
</param>
<param type="spacer" default="RESULTS" />
<param name="show_what" type="list" default="1" label="SHOW RESULTS AS" description="SHOW RESULTS AS DESC">
<option value="0">JOOMLA DEFAULT WAY</option>
<option value="1">PIE CHART</option>
</param>
<param name="show_hits" type="radio" default="1" label="SHOW HITS" description="SHOW HITS DESC">
<option value="1">Yes</option>
<option value="0">NO</option>
</param>
<param name="show_voters" type="radio" default="1" label="SHOW VOTERS" description="SHOW VOTERS DESC">
<option value="1">Yes</option>
<option value="0">NO</option>
</param>
<param name="show_times" type="radio" default="1" label="SHOW TIMES" description="SHOW TIMES DESC">
<option value="1">Yes</option>
<option value="0">NO</option>
</param>
<param name="show_dropdown" type="radio" default="1" label="SHOW DROPDOWN" description="SHOW DROPDOWN DESC">
<option value="1">Yes</option>
<option value="0">NO</option>
</param>
<param type="spacer" default="PIE OPTIONS" />
<param name="opacity" type="text" default="90" label="PIE TRANSPARANCY" description="PIE TRANSPARANCY DESC" size="2" />
<param name="bg_color" type="text" default="ffffff" label="BACKGROUND COLOR" description="BACKGROUND COLOR DESC" size="6" />
<param name="circle_color" type="text" default="505050" label="CIRCLE COLOR" description="CIRCLE COLOR DESC" size="6" />
<param name="pieX" type="text" default="100%" label="PIE WIDTH" description="PIE WIDTH DESC" size="3" />
<param name="pieY" type="text" default="400" label="PIE HEIGHT" description="PIE HEIGHT DESC" size="3" />
<param name="start_angle" type="text" default="55" label="START ANGLE" description="START ANGLE DESC" size="3" />
<param name="radius" type="text" default="150" label="RADIUS" description="RADIUS DESC" size="3" />
<param name="gradient" type="radio" default="1" label="GRADIENT" description="GRADIENT DESC" size="3">
<option value="1">Yes</option>
<option value="0">NO</option>
</param>
<param name="no_labels" type="radio" default="0" label="SHOW LABELS" description="SHOW LABELS DESC" size="3">
<option value="0">Yes</option>
<option value="1">NO</option>
</param>
<param name="show_zero_votes" type="radio" default="1" label="SHOW ZERO VOTES" description="SHOW ZERO VOTES DESC" size="3">
<option value="1">Yes</option>
<option value="0">NO</option>
</param>
<param name="animation_type" type="list" default="bounce" label="ANIMATION" description="ANIMATION DESC" size="3">
<option value="bounce">BOUNCE</option>
<option value="fade">FADE</option>
</param>
<param name="bounce_dinstance" type="text" default="30" label="BOUNCE DINSTANCE" description="BOUNCE DINSTANCE DESC" size="3" />
<param name="bg_image" type="imagelist" default="0" label="BACKGROUND IMAGE" description="BACKGROUND IMAGE DESC" directory="images/" hide_default ="true" />
<param name="bg_image_x" type="list" default="left" label="X POSITION" description="X POSITION DESC" size="3">
<option value="left">LEFT</option>
<option value="center">CENTER</option>
<option value="right">RIGHT</option>
</param>
<param name="bg_image_y" type="list" default="top" label="Y POSITION" description="Y POSITION DESC" size="3">
<option value="top">TOP</option>
<option value="middle">MIDDLE</option>
<option value="bottom">BOTTOM</option>
</param>
<param name="font_size" type="text" default="11" label="FONT SIZE OF LABELS" description="FONT SIZE LABELS DESC" size="3" />
<param name="font_color" type="text" default="404040" label="FONT COLOR OF LABELS" description="FONT COLOR DESC" size="6" />
<param name="title_lenght" type="text" default="30" label="OPTIONS LENGHT" description="OPTIONS LENGHT DESC" size="3" />
<param type="spacer" default="JOOMLA DEFAULT WAY" />
<param name="chartX" type="text" default="100%" label="CHART WIDTH" description="CHART WIDTH DESC" size="3" />
<param name="optionsFontSize" type="text" default="12" label="OPTIONS FONT SIZE" description="OPTION FONT SIZE DESC" size="3" />
<param name="barHeight" type="text" default="15" label="HEIGHT OF BARS" description="BAR HEIGHT DESC" size="3" />
<param name="barBorder" type="text" default="1px solid #000000" label="BARBORDER" description="BARBORDER DESC" size="20" />
<param name="bgBarColor" type="text" default="f5f5f5" label="BGBARCOLOR #" description="BGBARCOLOR DESC" size="6" />
<param name="bgBarBorder" type="text" default="1px solid #cccccc" label="BGBARBORDER" description="BGBARBORDER DESC" size="20" />
</params>
</root>
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,46 @@
<?php
# @file: administator/components/com_apoll/elements/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' );
class JElementApoll extends JElement
{
var $_name = 'Apoll';
function fetchElement($name, $value, &$node, $control_name)
{
$db =& JFactory::getDBO();
$query = 'SELECT a.id, a.title'
. ' FROM ' . $db->nameQuote("#__apoll_polls") . ' AS a'
. ' WHERE a.published = 1'
. ' ORDER BY a.title'
;
$db->setQuery( $query );
$options = $db->loadObjectList();
if(JRequest::getCmd('option') == "com_modules") {
array_unshift($options, JHTML::_('select.option', '', '- - - - - - - - - - -', 'id', 'title'));
array_unshift($options, JHTML::_('select.option', '0', JText::_('Show random poll'), 'id', 'title'));
} else {
array_unshift($options, JHTML::_('select.option', '0', '- - '.JText::_('Select Poll').' - -', 'id', 'title'));
}
return JHTML::_('select.genericlist', $options, ''.$control_name.'['.$name.']', 'class="inputbox"', 'id', 'title', $value, $control_name.$name );
}
}
@@ -0,0 +1 @@
<html><body bgcolor="#FFFFFF"></body></html>
@@ -0,0 +1,134 @@
<?php
# @version $Id: administator/components/com_apoll/install.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
defined( '_JEXEC' ) or die( 'Restricted access' );
function com_install()
{
$msg = "";
$db =& JFactory::getDBO();
//Check if we are updating the component from version 1.2 to 2.0
//If table #__apolls exists import the polls
if (in_array($db->getPrefix().'apolls', $db->getTableList())) {
//import the apolls table
$query = "INSERT INTO " . $db->nameQuote('#__apoll_polls') . " (id, title, alias, checked_out, checked_out_time, published, params, access, lag) SELECT id, title, alias, checked_out, checked_out_time, 0, params, access, lag/60 FROM " . $db->nameQuote('#__apolls') . ";";
$db->setQuery($query);
if(!$db->query()) {
$msg .= "<br />".$db->getErrorMsg();
} else {
$msg .= "<h3><img src='images/tick.png' style='float:left; margin-right:5px;'>".JText::_('Polls from version 1.2 successfully imported')."</h3>";
}
//copy the options table
$query = "INSERT INTO " . $db->nameQuote('#__apoll_options') . " (id, apoll_id, text, color, ordering) SELECT id, apollid, text, color, ordering FROM " . $db->nameQuote('#__apoll_data') . " WHERE text <> '';";
$db->setQuery( $query );
if(!$db->query()) {
$msg .= "<br />".$db->getErrorMsg();
} else {
$msg .= "<h3><img src='images/tick.png' style='float:left; margin-right:5px;'>".JText::_('Poll options from version 1.2 successfully imported')."</h3>";
}
//copy the votes table
$query = "INSERT INTO " . $db->nameQuote('#__apoll_votes') . " (id, date, option_id, apoll_id) SELECT id, date, vote_id, apoll_id FROM " . $db->nameQuote('#__apoll_date') . ";";
$db->setQuery( $query );
if(!$db->query()) {
$msg .= "<br />".$db->getErrorMsg();
} else {
$msg .= "<h3><img src='images/tick.png' style='float:left; margin-right:5px;'>".JText::_('Recorded votes from version 1.2 successfully imported')."</h3>";
}
// Find out Apoll component unique id
$query = "SELECT id FROM " . $db->nameQuote('#__components') . " WHERE link = " . $db->Quote('option=com_apoll');
$db->setQuery($query);
$component_id = $db->loadResult();
$query = "
UPDATE " . $db->nameQuote('#__components') . " SET admin_menu_img = '../media/system/images/apoll.png' WHERE id = $component_id;
INSERT INTO " . $db->nameQuote('#__components') . " VALUES
(null, 'Polls', '', 0, $component_id, 'option=com_apoll', 'Polls', 'com_apoll', 0, '', 0, '', 1),
(null, 'Votes', '', 0, $component_id, 'option=com_apoll&task=view&view=votes', 'Votes', 'com_apoll', 1, '', 0, '', 1),
(null, 'Configuration', '', 0, $component_id, 'option=com_apoll&task=view&view=config', 'Configuration', 'com_apoll', 2, '', 0, '', 1)
";
$db->setQuery( $query );
if(!$db->queryBatch()) {
$msg .= "<br />".$db->getErrorMsg();
} else {
$msg .= "<h3><img src='images/tick.png' style='float:left; margin-right:5px;'>".JText::_('Apoll admin menu successfully updated')."</h3>";
}
//Drop old tables
$db->setQuery("
DROP TABLE ". $db->nameQuote('#__apolls') . ";
DROP TABLE ". $db->nameQuote('#__apoll_data') .";
DROP TABLE ". $db->nameQuote('#__apoll_date').";
");
if(!$db->queryBatch()) {
$msg .= "<br />".$db->getErrorMsg();
} else {
$msg .= "<h3><img src='images/tick.png' style='float:left; margin-right:5px;'>".JText::_('Version 1.2 tables dropped')."</h3>";
}
}
// Change database apoll_votes' field vote_id to option_id.
$table = $db->getPrefix().'apoll_votes';
$fields = $db->getTableFields($table);
if(array_key_exists('vote_id', $fields[$table])) {
$db->setQuery("ALTER TABLE ". $db->nameQuote('#__apoll_votes') . " CHANGE ". $db->nameQuote('vote_id') . " ". $db->nameQuote('option_id') . " INT(11) NOT NULL DEFAULT '0'");
if(!$db->query()) {
$msg .= "ERROR!!! Field apoll_votes.vote_id exitsts. Could not be changed to apoll_votes.option_id. Please rename it manually.<br />".$db->getErrorMsg();
}
}
// Drop the #__apoll_menu table. We are getting rid of this table left from joomla 1.0
$db->setQuery("DROP TABLE IF EXISTS ". $db->nameQuote('#__apoll_menu'));
if(!$db->query()) {
$msg .= "<br />".$db->getErrorMsg();
}
//If Joomfish component is installed import apoll joomfish files
if (file_exists(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_joomfish'.DS.'config.xml'))
{
//Deletes older joomfish files
if (file_exists(JPATH_ADMINISTRATOR.DS."components".DS."com_joomfish".DS."contentelements".DS."apolls.xml") || file_exists(JPATH_ADMINISTRATOR.DS."components".DS."com_joomfish".DS."contentelements".DS."apoll_data.xml") || file_exists(JPATH_ADMINISTRATOR.DS."components".DS."com_joomfish".DS."contentelements".DS."apoll_poll.xml") || file_exists(JPATH_ADMINISTRATOR.DS."components".DS."com_joomfish".DS."contentelements".DS."apoll_options.xml")) {
//First files left from Apoll version 1.2
@unlink(JPATH_ADMINISTRATOR.DS."components".DS."com_joomfish".DS."contentelements".DS."apolls.xml");
@unlink(JPATH_ADMINISTRATOR.DS."components".DS."com_joomfish".DS."contentelements".DS."apoll_data.xml");
//Then check for files left from Apoll version 2.0
@unlink(JPATH_ADMINISTRATOR.DS."components".DS."com_joomfish".DS."contentelements".DS."apoll_polls.xml");
@unlink(JPATH_ADMINISTRATOR.DS."components".DS."com_joomfish".DS."contentelements".DS."apoll_options.xml");
}
//copy the files from com_apoll/joomfish to com_joomfish/contentelements and remove dir com_apoll/joomfish
if ((@rename(JPATH_ADMINISTRATOR.DS."components".DS."com_apoll".DS."joomfish".DS."apoll_polls.xml", JPATH_ADMINISTRATOR.DS."components".DS."com_joomfish".DS."contentelements".DS."apoll_polls.xml")) && (@rename(JPATH_ADMINISTRATOR.DS."components".DS."com_apoll".DS."joomfish".DS."apoll_options.xml", JPATH_ADMINISTRATOR.DS."components".DS."com_joomfish".DS."contentelements".DS."apoll_options.xml")) && (@rmdir (JPATH_ADMINISTRATOR.DS."components".DS."com_apoll".DS."joomfish"))) {
$msg .= "<h3><img src='images/tick.png' style='float:left; margin-right:5px;'>".JText::_('Joomfish component found! Contentelement files were also installed')."</h3>";
} else {
$msg .="<h3><img src='images/publish_x.png' style='float:left; margin-right:5px;'>".JText::_('Joomfish component was found, but content element files could not be copied')."</h3>";}
}
?>
<div class="header"><?php echo JText::_('Congratulations, Apoll component version 2.0 is successfully installed!'); ?></div>
<p>
<br />
<?php echo $msg; ?>
</p>
<?php } ?>
@@ -0,0 +1,60 @@
--
-- Table structure for table `#__apolls`
--
CREATE TABLE IF NOT EXISTS `#__apoll_polls` (
`id` int(11) unsigned NOT NULL auto_increment,
`title` varchar(255) NOT NULL default '',
`alias` varchar(255) NOT NULL default '',
`checked_out` int(11) NOT NULL default '0',
`checked_out_time` datetime NOT NULL default '0000-00-00 00:00:00',
`published` tinyint(1) NOT NULL default '0',
`publish_up` datetime NOT NULL default '0000-00-00 00:00:00',
`publish_down` datetime default '0000-00-00 00:00:00',
`params` text NOT NULL,
`access` int(11) NOT NULL default '0',
`lag` int(11) NOT NULL default '0',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=0 ;
--
-- Table structure for table '#__apoll_options'
--
CREATE TABLE IF NOT EXISTS `#__apoll_options` (
`id` int(11) NOT NULL auto_increment,
`apoll_id` int(11) NOT NULL default '0',
`text` text NOT NULL,
`link` varchar(255) DEFAULT NULL,
`color` varchar(6) NOT NULL,
`ordering` int(11) NOT NULL,
PRIMARY KEY (`id`),
KEY `apoll_id` (`apoll_id`,`text`(1))
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=0 ;
--
-- Table structure for table '#__apoll_votes'
--
CREATE TABLE IF NOT EXISTS `#__apoll_votes` (
`id` bigint(20) NOT NULL auto_increment,
`date` datetime NOT NULL default '0000-00-00 00:00:00',
`option_id` int(11) NOT NULL default '0',
`apoll_id` int(11) NOT NULL default '0',
`ip` int(10) unsigned NOT NULL,
`user_id` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `apoll_id` (`apoll_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=0 ;
--
-- Table structure for table '#__apoll_config'
--
CREATE TABLE IF NOT EXISTS `#__apoll_config` (
`drop_it` tinyint(1) NOT NULL DEFAULT '0'
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
INSERT INTO `#__apoll_config` (`drop_it`) VALUES ('0');
@@ -0,0 +1,86 @@
<?xml version="1.0" encoding="utf-8"?>
<install type="component" version="1.5.0">
<name>Apoll</name>
<creationDate>October 2009</creationDate>
<author>Hristo Genev</author>
<authorEmail>[email protected]</authorEmail>
<authorUrl>http://www.afactory.org</authorUrl>
<copyright>Hristo Genev. All rights reserved.</copyright>
<license>GPL/GNU</license>
<version>2.0.016</version>
<description>Apoll is a component for voting. It shows vote results with a nice pie chart. Basicly it substitutes the original poll component installed in Joomla by default and adds some enhancements to the back and front end.</description>
<installfile>install.apoll.php</installfile>
<uninstallfile>uninstall.apoll.php</uninstallfile>
<files folder="site">
<filename>controller.php</filename>
<filename>apoll.php</filename>
<filename>index.html</filename>
<filename>router.php</filename>
<folder>models</folder>
<folder>views</folder>
</files>
<languages folder="languages/site">
<language tag="en-GB">en-GB.com_apoll.ini</language>
</languages>
<media folder="media" destination="system">
<filename>js/jquery.apoll.js</filename>
<filename>js/jquery.tablednd.js</filename>
<filename>js/jquery.colorpicker.js</filename>
<filename>js/jquery.color.js</filename>
<filename>js/jquery.js</filename>
<filename>js/json.js</filename>
<filename>swf/open-flash-chart.swf</filename>
<filename>images/apoll-arrow.gif</filename>
<filename>images/apoll.png</filename>
<filename>images/apoll-add.png</filename>
<filename>images/apoll-remove.png</filename>
<filename>images/apoll-ended.gif</filename>
<filename>images/apoll-active.gif</filename>
</media>
<install>
<sql>
<file charset="utf8" driver="mysql">install.sql</file>
</sql>
</install>
<uninstall>
<sql>
<file charset="utf8" driver="mysql">uninstall.sql</file>
</sql>
</uninstall>
<administration>
<!-- Administration Menu Section -->
<menu img="../media/system/images/apoll.png" link="option=com_apoll">Apolls</menu>
<submenu>
<menu img="" link="option=com_apoll">Polls</menu>
<menu img="" link="option=com_apoll&amp;task=view&amp;view=votes">Votes</menu>
<menu img="" link="option=com_apoll&amp;task=view&amp;view=config">Configuration</menu>
</submenu>
<files folder="administrator">
<!-- Site Main File Copy Section -->
<filename>apoll.php</filename>
<filename>config.xml</filename>
<filename>controller.php</filename>
<filename>index.html</filename>
<filename>install.apoll.php</filename>
<filename>uninstall.apoll.php</filename>
<filename>install.sql</filename>
<filename>uninstall.sql</filename>
<folder>models</folder>
<folder>tables</folder>
<folder>views</folder>
<folder>elements</folder>
<!-- Joomfish files added in version 1.2 -->
<folder>joomfish</folder>
</files>
<languages folder="languages/admin">
<language tag="en-GB">en-GB.com_apoll.ini</language>
<language tag="en-GB">en-GB.com_apoll.menu.ini</language>
</languages>
</administration>
</install>
@@ -0,0 +1,17 @@
<?xml version="1.0" ?>
<joomfish type="contentelement">
<name>Apoll - Options</name>
<author>Hristo Genev</author>
<version>2.0</version>
<description>Definition for the Apoll poll options</description>
<reference>
<table name="apoll_options">
<field type="referenceid" name="id" translate="0">ID</field>
<field type="titletext" name="text" translate="1">Option</field>
</table>
</reference>
<translationfilters>
<apolloptions_empty>text</apolloptions_empty>
<apollname>apoll_id</apollname>
</translationfilters>
</joomfish>
@@ -0,0 +1,15 @@
<?xml version="1.0" ?>
<joomfish type="contentelement">
<name>Apoll - Polls</name>
<author>Hristo Genev</author>
<version>2.0</version>
<description>Definition for the core Apoll component</description>
<reference>
<table name="apoll_polls">
<field type="referenceid" name="id" translate="0">ID</field>
<field type="titletext" name="title" translate="1">Title</field>
<field type="text" name="alias" translate="1" posthandler="filterTitle">Alias</field>
</table>
</reference>
</joomfish>
@@ -0,0 +1,192 @@
<?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 Apoll
*/
class ApollsModelApoll extends JModel
{
var $_id = null;
var $_data = null;
/**
* Store petition
* @param int The id of the poll
* @param int The id of the option selected
*/
function __construct()
{
parent::__construct();
$array = JRequest::getVar('cid', array(0), '', 'array');
$edit = JRequest::getVar('edit',true);
if($edit)
$this->setId((int)$array[0]);
}
function setId($id)
{
// Set apoll id and wipe data
$this->_id = $id;
$this->_data = null;
}
/**
* Method to get a apoll
*
* @since 1.5
*/
function &getData()
{
// Load the apoll data
if ($this->_loadData())
{
// Initialize some variables
$user = &JFactory::getUser();
}
else $this->_initData();
return $this->_data;
}
function isCheckedOut( $uid=0 )
{
if ($this->_loadData())
{
if ($uid) {
return ($this->_data->checked_out && $this->_data->checked_out != $uid);
} else {
return $this->_data->checked_out;
}
}
}
function checkin()
{
if ($this->_id)
{
$apoll = & $this->getTable();
if(! $apoll->checkin($this->_id)) {
$this->setError($this->_db->getErrorMsg());
return false;
}
}
return false;
}
function checkout($uid = null)
{
if ($this->_id)
{
// Make sure we have a user id to checkout the article with
if (is_null($uid)) {
$user =& JFactory::getUser();
$uid = $user->get('id');
}
// Lets get to it and checkout the thing...
$apoll =& $this->getTable();
if(!$apoll->checkout($uid, $this->_id)) {
$this->setError($this->_db->getErrorMsg());
return false;
}
return true;
}
return false;
}
function store($data)
{
$row =& $this->getTable();
// Bind the form fields to the web link table
if (!$row->bind($data)) {
$this->setError($this->_db->getErrorMsg());
return false;
}
// Create the timestamp for the date
$row->date = gmdate('Y-m-d H:i:s');
// Make sure the web link table is valid
if (!$row->check()) {
$this->setError($this->_db->getErrorMsg());
return false;
}
// Store the web link table to the database
if (!$row->store()) {
$this->setError($this->_db->getErrorMsg());
return false;
}
return true;
}
function _loadData()
{
// Lets load the content if it doesn't already exist
if (empty($this->_data))
{
/* $db =& JFactory::getDBO();
$query = "SELECT d.*, COUNT(v.id) AS hits"
." FROM ".$db->nameQuote('#__apoll_options')." AS d"
." LEFT JOIN ".$db->nameQuote('#__apoll_votes')." AS v"
." ON d.id=v.option_id"
." WHERE d.apoll_id = ".(int) $this->_id
." AND text<>'' GROUP BY d.id ORDER BY ordering";
$this->_db->setQuery($query);
$this->_data = $this->_db->loadObject();
*/ return (boolean) $this->_data;
}
return true;
}
function _initData()
{
// Lets load the content if it doesn't already exist
if (empty($this->_data))
{
$apoll = new stdClass();
$apoll->id = 0;
$apoll->title = null;
$apoll->alias = null;
$apoll->checked_out = 0;
$apoll->checked_out_time = 0;
$apoll->published = 0;
$apoll->params = null;
$apoll->access = null;
$apoll->lag = 0;
$this->_data = $apoll;
return (boolean) $this->_data;
}
return true;
}
//delete empty options to clear the db
function deleteOption($id) {
$query = "DELETE FROM ".$this->_db->nameQuote('#__apoll_options')." WHERE ".$this->_db->nameQuote('id')."=".$this->_db->Quote((int)$id)." LIMIT 1";
$this->_db->setQuery($query);
if(!$this->_db->query()) {
$this->setError($this->_db->getErrorMsg());
return false;
}
return true;
}
}
?>
@@ -0,0 +1,106 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<params>
<param type="spacer" default="VOTING" />
<param name="only_registered" type="radio" default="0" label="ONLY REGISTERED" description="ONLY REGISTERED DESC">
<option value="1">Yes</option>
<option value="0">NO</option>
</param>
<param name="one_vote_per_user" type="radio" default="1" label="ONE VOTE PER USER" description="ONE VOTE PER USER DESC">
<option value="1">Yes</option>
<option value="0">NO</option>
</param>
<param name="ip_check" type="radio" default="0" label="ONE VOTE PER IP" description="ONE VOTE PER IP DESC">
<option value="1">Yes</option>
<option value="0">NO</option>
</param>
<param name="show_component_msg" type="radio" default="1" label="SHOW MSG" description="SHOW MSG DESC">
<option value="1">Yes</option>
<option value="0">NO</option>
</param>
<param name="allow_voting" type="radio" default="1" label="ALLOW VOTING" description="ALLOW VOTING DESC">
<option value="1">Yes</option>
<option value="0">NO</option>
</param>
<param type="spacer" default="RESULTS" />
<param name="show_what" type="list" default="1" label="SHOW RESULTS AS" description="SHOW RESULTS AS DESC">
<option value="0">JOOMLA DEFAULT WAY</option>
<option value="1">PIE CHART</option>
</param>
<param name="show_hits" type="radio" default="1" label="SHOW HITS" description="SHOW HITS DESC">
<option value="1">Yes</option>
<option value="0">NO</option>
</param>
<param name="show_title" type="radio" default="1" label="SHOW TITLE" description="SHOW TITLE DESC">
<option value="1">Yes</option>
<option value="0">No</option>
</param>
<param name="show_dropdown" type="radio" default="1" label="SHOW DROPDOWN" description="SHOW DROPDOWN DESC">
<option value="1">Yes</option>
<option value="0">NO</option>
</param>
<param name="show_voters" type="radio" default="1" label="SHOW VOTERS" description="SHOW VOTERS DESC">
<option value="1">Yes</option>
<option value="0">NO</option>
</param>
<param name="show_times" type="radio" default="1" label="SHOW TIMES" description="SHOW TIMES DESC">
<option value="1">Yes</option>
<option value="0">NO</option>
</param>
</params>
<params group="pieoptions">
<param name="opacity" type="text" default="90" label="PIE TRANSPARANCY" description="PIE TRANSPARANCY DESC" size="2" />
<param name="bg_color" type="text" default="ffffff" label="BACKGROUND COLOR" description="BACKGROUND COLOR DESC" size="6" />
<param name="circle_color" type="text" default="505050" label="CIRCLE COLOR" description="CIRCLE COLOR DESC" size="6" />
<param name="pieX" type="text" default="100%" label="PIE WIDTH" description="PIE WIDTH DESC" size="3" />
<param name="pieY" type="text" default="400" label="PIE HEIGHT" description="PIE HEIGHT DESC" size="3" />
<param name="start_angle" type="text" default="55" label="START ANGLE" description="START ANGLE DESC" size="3" />
<param name="radius" type="text" default="150" label="RADIUS" description="RADIUS DESC" size="3" />
<param name="gradient" type="radio" default="1" label="GRADIENT" description="GRADIENT DESC" size="3">
<option value="1">Yes</option>
<option value="0">NO</option>
</param>
<param name="no_labels" type="radio" default="0" label="SHOW LABELS" description="SHOW LABELS DESC" size="3">
<option value="0">Yes</option>
<option value="1">NO</option>
</param>
<param name="show_zero_votes" type="radio" default="1" label="SHOW ZERO VOTES" description="SHOW ZERO VOTES DESC" size="3">
<option value="1">Yes</option>
<option value="0">NO</option>
</param>
<param name="animation_type" type="list" default="bounce" label="ANIMATION" description="ANIMATION DESC" size="3">
<option value="bounce">BOUNCE</option>
<option value="fade">FADE</option>
</param>
<param name="bounce_dinstance" type="text" default="30" label="BOUNCE DINSTANCE" description="BOUNCE DINSTANCE DESC" size="3" />
<param name="bg_image" type="imagelist" default="0" label="BACKGROUND IMAGE" description="BACKGROUND IMAGE DESC" directory="images/" hide_default ="true" />
<param name="bg_image_x" type="list" default="left" label="X POSITION" description="X POSITION DESC" size="3">
<option value="left">LEFT</option>
<option value="center">CENTER</option>
<option value="right">RIGHT</option>
</param>
<param name="bg_image_y" type="list" default="top" label="Y POSITION" description="Y POSITION DESC" size="3">
<option value="top">TOP</option>
<option value="middle">MIDDLE</option>
<option value="bottom">BOTTOM</option>
</param>
<param name="font_size" type="text" default="11" label="FONT SIZE OF LABELS" description="FONT SIZE LABELS DESC" size="3" />
<param name="font_color" type="text" default="404040" label="FONT COLOR OF LABELS" description="FONT COLOR DESC" size="6" />
<param name="title_lenght" type="text" default="30" label="OPTIONS LENGHT" description="OPTIONS LENGHT DESC" size="3" />
</params>
<params group="joomladefault">
<param name="chartX" type="text" default="100%" label="CHART WIDTH" description="CHART WIDTH DESC" size="3" />
<param name="optionsFontSize" type="text" default="12" label="OPTIONS FONT SIZE" description="OPTION FONT SIZE DESC" size="3" />
<param name="barHeight" type="text" default="15" label="HEIGHT OF BARS" description="BAR HEIGHT DESC" size="3" />
<param name="barBorder" type="text" default="1px solid #000000" label="BARBORDER" description="BARBORDER DESC" size="20" />
<param name="bgBarColor" type="text" default="f5f5f5" label="BGBARCOLOR #" description="BGBARCOLOR DESC" size="6" />
<param name="bgBarBorder" type="text" default="1px solid #cccccc" label="BGBARBORDER" description="BGBARBORDER DESC" size="20" />
</params>
</root>
@@ -0,0 +1,192 @@
<?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 ApollsModelApolls 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
$limit = $mainframe->getUserStateFromRequest( 'global.list.limit', 'limit', $mainframe->getCfg('list_limit'), 'int' );
$limitstart = $mainframe->getUserStateFromRequest( $option.'limitstart.apolls', 'limitstart', 0, 'int' );
// In case limit has been changed, adjust limitstart accordingly
$limitstart = ($limit != 0 ? (floor($limitstart / $limit) * $limit) : 0);
$this->setState('limit', $limit);
$this->setState('limitstart', $limitstart);
}
/**
* Method to get weblinks 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()
{
// Get the WHERE and ORDER BY clauses for the query
$where = $this->_buildContentWhere();
$orderby = $this->_buildContentOrderBy();
$db =& JFactory::getDBO();
$query = "SELECT m.*, u.name AS editor, COUNT(o.id) AS options, ( SELECT count(v.id) FROM ".$db->nameQuote('#__apoll_votes')." AS v
WHERE v.apoll_id=m.id) AS votes FROM ".$db->nameQuote('#__apoll_polls')." AS m
LEFT JOIN ".$db->nameQuote('#__users')." AS u ON u.id= m.checked_out
LEFT JOIN ".$db->nameQuote('#__apoll_options')." AS o ON o.apoll_id = m.id 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' );
$filter_state = $mainframe->getUserStateFromRequest( "$option.filter_state.apolls", 'filter_state', '', '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 );
}
if ( $filter_state ) {
if ( $filter_state == 'P' ) {
$where[] = 'm.published = 1';
} else if ($filter_state == 'U' ) {
$where[] = 'm.published = 0';
}
}
$where = ( count( $where ) ? ' WHERE '. implode( ' AND ', $where ) : '' );
return $where;
}
function resetVotes($cid = Null) {
$db =& JFactory::getDBO();
$cid = JRequest::getVar( 'cid', array(), '', 'array' );
JArrayHelper::toInteger($cid);
$cids = implode( ',', $cid );
$query = "DELETE FROM ".$db->nameQuote('#__apoll_votes')." WHERE ".$db->nameQuote('apoll_id')." IN (".$cids.")";
$db->setQuery($query);
if($db->query()) {
return true;
} else {
return false;
}
}
}
?>
@@ -0,0 +1,238 @@
<?php
# @version $Id: components/com_apoll/models/config.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 ApollsModelConfig extends JModel
{
var $_data = null;
function getData()
{
$db =& JFactory::getDBO();
$query = "SELECT " . $db->nameQuote('drop_it') . " FROM #__apoll_config";
$db->setQuery($query);
$this->_data = $db->loadResult();
return $this->_data;
}
function save()
{
$db =& JFactory::getDBO();
$drop = JRequest::getVar('drop', 0, 'POST', 'INT');
$query = "UPDATE ".$db->nameQuote('#__apoll_config')."
SET ".$db->nameQuote('drop_it')."=".(int)$drop;
$db->setQuery($query);
if (!$db->query()) {
JError::raiseError ($db->stderr());
return false;
}
return true;
}
function getApolls()
{
$db =& JFactory::getDBO();
$query = "SELECT COUNT(id) FROM ".$db->nameQuote('#__apoll_polls');
$db->setQuery($query);
if($result = $db->loadResult()) {
return $result;
} else {
return false;
}
}
function getJpolls()
{
$db =& JFactory::getDBO();
$query = "SELECT COUNT(id) FROM ".$db->nameQuote('#__polls');
$db->setQuery($query);
if($result = $db->loadResult()) {
return $result;
} else {
return false;
}
}
/**
* Function to import polls from joomla poll component
* 1. Copy #__polls table with all polls to #__apoll_polls
* 2. Get the id of the first newly created poll
* 3. Get all polls' ids from #__polls table and push the into an array
* 4. Copy the options from #__poll_data to #__apoll_options
* 5. Generate random color for each options
* 6. Correct apoll_id of the options
* 7. Copy votes from #__poll_date to #__apoll_votes
* 8. Correct apoll_id field of all votes
*/
function import()
{
$db =& JFactory::getDBO();
//import the polls table
$query = "
INSERT INTO " . $db->nameQuote('#__apoll_polls') . "
(title, alias, checked_out, checked_out_time, published, params, access, lag)
SELECT title, alias, checked_out, checked_out_time, 0, 'only_registered=0\none_vote_per_user=1\nip_check=0\nshow_component_msg=1\nallow_voting=1\nshow_what=1\nshow_hits=1\nshow_title=1\nshow_dropdown=1\nshow_voters=1\nshow_times=1\nopacity=90\nbg_color=ffffff\ncircle_color=505050\npieX=100%\npieY=400\nstart_angle=55\nradius=150\ngradient=1\nno_labels=0\nshow_zero_votes=1\nanimation_type=bounce\nbounce_dinstance=30\nbg_image=-1\nbg_image_x=left\nbg_image_y=top\nfont_size=11\nfont_color=404040\ntitle_lenght=30\nchartX=100%\noptionsFontSize=12\nbarHeight=15\nbarBorder=1px solid #000000\nbgBarColor=f5f5f5\nbgBarBorder=1px solid #cccccc\n', access, lag/60
FROM " . $db->nameQuote('#__polls') . " ;";
$db->setQuery( $query );
if(!$db->query()) return false;
//get the first new id of the imported polls
$new_id = $db->insertid();
//get the native polls ids and put them in an array
$query = "SELECT id FROM ". $db->nameQuote('#__polls');
$db->setQuery($query);
$old_ids = $db->loadResultArray();
//copy the options table
$query = "INSERT INTO " . $db->nameQuote('#__apoll_options') . " (apoll_id, text, color)
SELECT pollid, text, 'cccccc'
FROM " . $db->nameQuote('#__poll_data') . "
WHERE text <>'';"
;
$db->setQuery( $query );
if(!$db->query()) return false;
//get the id of the first option
$new_option_id = $db->insertid();
//get how many polls are imported
$n = $db->getAffectedRows();
//generate random color for each new option
$id = $new_option_id;
for ($i=0; $i<$n; $i++) {
$query = "UPDATE ". $db->nameQuote('#__apoll_options')."
SET color = '". $this->random_color() ."'
WHERE id = ".$id;
$id++;
$db->setQuery( $query );
$db->query();
}
$query = "";
//correct apoll_ids of options and generate random colors
$id = $new_id;
foreach ($old_ids as $value) {
$query = "UPDATE " . $db->nameQuote('#__apoll_options') . "
SET apoll_id = ". $id ."
WHERE apoll_id = ". $value . ";";
$id++;
$db->setQuery( $query );
$db->query();
}
//copy the votes table
$query = "INSERT INTO ". $db->nameQuote('#__apoll_votes')." (date, apoll_id, option_id)
SELECT date, poll_id, vote_id
FROM " . $db->nameQuote('#__poll_date') . ";"
;
$db->setQuery( $query );
if(!$db->query())
return false;
$query = "";
//correct apoll_ids of votes
$id = $new_id; //reset the id
foreach ($old_ids as $value) {
$query = "UPDATE " . $db->nameQuote('#__apoll_votes') . "
SET apoll_id = " . $id . "
WHERE apoll_id = " . $value. ";";
$id++;
$db->setQuery( $query );
$db->query();
}
//correct apoll_ids of votes
$query = "";
//put all old ids of old options from #__poll_data table in array
$query = "SELECT id FROM " . $db->nameQuote('#__poll_data') . " WHERE text <> ''";
$db->setQuery($query);
$old_option_ids = $db->loadResultArray();
$id = $new_option_id;
foreach ($old_option_ids as $value) {
$query = "UPDATE " . $db->nameQuote('#__apoll_votes') . "
SET option_id = $id
WHERE option_id = $value;";
$id++;
$db->setQuery( $query );
$db->query();
}
return true;
}
// random color generator
function random_color(){
mt_srand((double)microtime()*1000000);
$c = '';
while(strlen($c)<6){
$c .= sprintf("%02X", mt_rand(0, 255));
}
return $c;
}
function getJoomfishInstalled() {
if (file_exists(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_joomfish'.DS.'config.xml'))
return true;
return false;
}
function getApollFilesInstalled() {
if (file_exists(JPATH_ADMINISTRATOR.DS."components".DS."com_joomfish".DS."contentelements".DS."apoll_polls.xml") && file_exists(JPATH_ADMINISTRATOR.DS."components".DS."com_joomfish".DS."contentelements".DS."apoll_options.xml"))
return true;
return false;
}
function getApollFilesPresent() {
if (file_exists(JPATH_ADMINISTRATOR.DS."components".DS."com_apoll".DS."joomfish".DS."apoll_polls.xml") && file_exists(JPATH_ADMINISTRATOR.DS."components".DS."com_apoll".DS."joomfish".DS."apoll_options.xml"))
return true;
return false;
}
function copyJoomfishFiles() {
//copy the files from com_apoll/joomfish to com_joomfish/contentelements and remove dir com_apoll/joomfish
if((@rename(JPATH_ADMINISTRATOR.DS."components".DS."com_apoll".DS."joomfish".DS."apoll_polls.xml", JPATH_ADMINISTRATOR.DS."components".DS."com_joomfish".DS."contentelements".DS."apoll_polls.xml"))
&&
(@rename(JPATH_ADMINISTRATOR.DS."components".DS."com_apoll".DS."joomfish".DS."apoll_options.xml", JPATH_ADMINISTRATOR.DS."components".DS."com_joomfish".DS."contentelements".DS."apoll_options.xml"))
&&
(@rmdir (JPATH_ADMINISTRATOR.DS."components".DS."com_apoll".DS."joomfish")))
{
return true;
}
return false;
}
}
?>
@@ -0,0 +1 @@
<html><body bgcolor="#FFFFFF"></body></html>
@@ -0,0 +1,199 @@
<?php
# @file: administrator/components/com_apoll/models/votes.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' );
class ApollsModelVotes extends JModel
{
var $_data = null;
var $_total = null;
var $_pagination = null;
function __construct()
{
parent::__construct();
global $mainframe, $option;
// Get the pagination request variables
$limit = $mainframe->getUserStateFromRequest( 'global.list.limit', 'limit', $mainframe->getCfg('list_limit'), 'int' );
$limitstart = $mainframe->getUserStateFromRequest( $option.'limitstart.votes', 'limitstart', 0, 'int' );
// In case limit has been changed, adjust limitstart accordingly
$limitstart = ($limit != 0 ? (floor($limitstart / $limit) * $limit) : 0);
$this->setState('limit', $limit);
$this->setState('limitstart', $limitstart);
}
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'));
}
//DEBUG
//echo str_replace('#__', 'jos_', $query); exit;
return $this->_data;
}
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;
}
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()
{
$db =& JFactory::getDBO();
$query = "SELECT v.id, v.date, o.text, INET_NTOA(ip) AS ip,
CASE WHEN v.user_id <> 0 THEN u.name ELSE ".$db->Quote(JText::_('Guest'))." END AS name
FROM " . $db->nameQuote('#__apoll_votes') . " AS v
LEFT JOIN " . $db->nameQuote('#__apoll_options') . " AS o ON o.id = v.option_id
LEFT JOIN " . $db->nameQuote('#__users') . " AS u ON u.id=v.user_id "
// Get the WHERE and ORDER BY clauses for the query
. $this->_buildContentWhere()
. $this->_buildContentOrderBy();
return $query;
}
function _buildContentOrderBy()
{
global $mainframe, $option;
$filter_order = $mainframe->getUserStateFromRequest( "$option.filter_order.votes", 'filter_order', 'v.date', 'cmd' );
$filter_order_Dir = $mainframe->getUserStateFromRequest( "$option.filter_order_Dir.votes", '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.votes", 'filter_order', 'v.date', 'cmd' );
$filter_order_Dir = $mainframe->getUserStateFromRequest( "$option.filter_order_Dir.votes", 'filter_order_Dir', '', 'word' );
$search = $mainframe->getUserStateFromRequest( "$option.search.votes",'search','','string');
$where = array();
$apoll_id = JRequest::getInt('id', 0, 'GET');
$where[] = " v.apoll_id = " . $apoll_id;
if ($search)
{
$search = JString::strtolower( $search );
$search = $db->Quote('%'.$db->getEscaped( $search, true ).'%', false );
$where[]= ' LOWER(u.name) LIKE ' . $search;
}
$where = ' WHERE '. implode( ' AND ', $where );
return $where;
}
function getList() {
$db =& JFactory::getDBO();
$apoll_id = JRequest::getInt('id', 0, 'GET');
// list of apolls for dropdown selection
$query = "SELECT m.id, m.title, COUNT(v.id) AS votes"
. " FROM ".$db->nameQuote('#__apoll_polls')." AS m"
. " LEFT JOIN ".$db->nameQuote('#__apoll_votes')." AS v"
. " ON m.id=v.apoll_id"
. " GROUP BY m.id ORDER BY id";
$db->setQuery( $query );
$pList = $db->loadObjectList();
//Get the title for the site=the active poll
foreach ($pList as $p) {
if ($p->id==$apoll_id) $title=$p->title;
}
//Make the URLs for the dropdown
foreach ($pList as $k=>$p)
{
$pList[$k]->url = JRoute::_('index.php?option=com_apoll&task=view&view=votes&id='.$p->id);
}
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&task=view&view=votes&id='.$apoll_id)
);
return $lists;
}
function getTitle() {
$db =& JFactory::getDBO();
$apoll_id = JRequest::getInt('id', 0, 'GET');
$query = "SELECT title FROM ".$db->nameQuote('#__apoll_polls')." WHERE ".$db->nameQuote('id')."=".(int)$apoll_id;
$db->setQuery($query);
return $db->loadResult();
}
function deleteVotes() {
$db =& JFactory::getDBO();
$cid = JRequest::getVar( 'cid', array(), '', 'array' );
JArrayHelper::toInteger($cid);
$cids = implode(',', $cid);
//Delete the chosen votes, dates, ips, users, etc from #__apolls_date table
$query = "DELETE FROM ".$db->nameQuote('#__apoll_votes')." WHERE id IN (" . $cids . ")";
$db->setQuery($query);
if(!$db->query()) {
return false;
} else {
return true;
}
}
}
?>
@@ -0,0 +1,156 @@
<?php
# @version $Id: administator/components/com_apoll/tables/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' );
/**
* @package Joomla
* @subpackage Polls
*/
class TableApoll extends JTable
{
/** @var int Primary key */
var $id = 0;
/** @var string */
var $title = '';
/** @var string */
var $alias = '';
/** @var string */
var $checked_out = 0;
/** @var time */
var $checked_out_time = 0;
/** @var boolean */
var $published = 0;
/** @var boolean */
var $publish_up = 0;
/** @var boolean */
var $publish_down = 0;
/* @var string */
var $params = null;
/** @var int */
var $access = 0;
/** @var int */
var $lag = 0;
/**
* @param database A database connector object
*/
function __construct( &$db )
{
parent::__construct( '#__apoll_polls', 'id', $db );
}
/**
* Binds an array to the object
* @param array Named array
* @param string Space separated list of fields not to bind
* @return boolean
*/
function bind($array, $ignore = '')
{
if (key_exists( 'params', $array ) && is_array( $array['params'] ))
{
$registry = new JRegistry();
$registry->loadArray($array['params']);
$array['params'] = $registry->toString();
}
return parent::bind($array, $ignore);
}
/**
* Overloaded check function
*
* @access public
* @return boolean
* @see JTable::check
* @since 1.5
*/
function check()
{
global $mainframe;
// check for valid name
if (trim( $this->title ) == '')
{
$this->setError(JText::_( 'Your Poll must contain a title.' ));
return false;
}
// check for valid lag
$this->lag = floatval( $this->lag*60 );
if ($this->lag == 0) {
$this->setError(JText::_( 'Your Poll must have a non-zero lag time.' ));
return false;
}
if(empty($this->alias)) {
$this->alias = $this->title;
}
$this->alias = JFilterOutput::stringURLSafe($this->alias);
if(trim(str_replace('-','',$this->alias)) == '') {
$datenow =& JFactory::getDate();
$datenow->setOffset($mainframe->getCfg('offset'));
$this->alias = $datenow->toFormat("%Y-%m-%d-%H-%M-%S");
}
return true;
}
// overloaded delete function
function delete( $oid=null )
{
$k = $this->_tbl_key;
if ( $oid ) {
$this->$k = intval( $oid );
}
if ( parent::delete( $oid ))
{
$db =& JFactory::getDBO();
$query = "DELETE FROM ".$db->nameQuote('#__apoll_options')
." WHERE ".$db->nameQuote('apoll_id')."=".(int) $oid.";";
$query .= "DELETE FROM ". $db->nameQuote('#__apoll_votes').
" WHERE ".$db->nameQuote('apoll_id')."=".(int)$oid.";";
$db->setQuery($query);
$db->queryBatch( $query );
if ( !$db->query() ) {
$this->_error .= $db->getErrorMsg() . "\n";
}
return true;
}
return false;
}
// function to get the options for current poll
function getOptions($apoll_id) {
$query = "SELECT o.*, COUNT(v.id) AS hits"
." FROM ".$this->_db->nameQuote('#__apoll_options')." AS o"
." LEFT JOIN ".$this->_db->nameQuote('#__apoll_votes')." AS v"
." ON (o.id = v.option_id AND v.apoll_id = ".(int) $apoll_id . ")"
." WHERE o.apoll_id = ".(int) $apoll_id
." AND text <> '' GROUP BY o.id ORDER BY o.ordering";
//print nl2br(str_replace('#__', 'jos_', $query)); exit;
$this->_db->setQuery($query);
return $this->_db->loadObjectList();
}
}
@@ -0,0 +1 @@
<html><body bgcolor="#FFFFFF"></body></html>
@@ -0,0 +1,52 @@
<?php
# @version $Id: administator/components/com_apoll/uninstall.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
defined( '_JEXEC' ) or die( 'Restricted access' );
function com_uninstall()
{
$msg = "";
$db =& JFactory::getDBO();
$query = "SELECT " . $db->nameQuote('drop_it') . " FROM " . $db->nameQuote('#__apoll_config');
$db->setQuery($query);
if ($db->loadResult()) {
$query = "
DROP TABLE IF EXISTS ". $db->nameQuote('#__apoll_polls') . ";
DROP TABLE IF EXISTS ". $db->nameQuote('#__apoll_options') . ";
DROP TABLE IF EXISTS ". $db->nameQuote('#__apoll_votes') . ";
DROP TABLE IF EXISTS ". $db->nameQuote('#__apoll_menu') . ";
DROP TABLE IF EXISTS ". $db->nameQuote('#__apoll_config;')
;
$db->setQuery($query);
if (!$db->queryBatch()) {
$db->stderr();
} else {
$msg = "Apoll database has been successfully dropped.";
}
} else {
$msg = "Apoll database has not been dropped.";
}
$query = "DELETE FROM " . $db->nameQuote('#__apoll_config');
$db->setQuery($query);
$db->query();
?>
<div class="header"><?php echo JText::_("The Apoll component is now removed from your system. We're sorry to see you go!"); ?></div>
<?php
echo "<p>".JText::_($msg)."</p>";
}
?>
@@ -0,0 +1 @@
<html><body bgcolor="#FFFFFF"></body></html>
@@ -0,0 +1,40 @@
<?php
# @version $Id: administator/components/com_apoll/views/apoll/tmpl/default.php 0001 2009-03-08 18:12
# @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');
?>
<form>
<table align="center" width="90%" cellspacing="2" cellpadding="2" border="0" >
<tr>
<td class="moduleheading" colspan="2"><?php echo $this->apoll->title; ?></td>
</tr>
<?php foreach ($this->options as $option)
{
if ($option->text <> "")
{?>
<tr>
<td valign="top" height="30"><input type="radio" name="apoll" value="<?php echo $option->text; ?>"></td>
<td class="apoll" width="100%" valign="top"><?php echo $option->text; ?></td>
</tr>
<?php }
} ?>
<tr>
<td valign="middle" height="50" colspan="2" align="center"><input type="button" name="submit" value="<?php echo JText::_( 'Vote' ); ?>">&nbsp;&nbsp;<input type="button" name="result" value="<?php echo JText::_( 'Results' ); ?>"></td>
</tr>
</table>
</form>
File diff suppressed because it is too large Load Diff
@@ -0,0 +1 @@
<html><body bgcolor="#FFFFFF"></body></html>
@@ -0,0 +1,79 @@
<?php
# @version $Id: administator/components/com_apoll/views/apoll/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');
class ApollsViewApoll extends JView
{
function display($tpl = null)
{
global $mainframe;
$db =& JFactory::getDBO();
$user =& JFactory::getUser();
$cid = JRequest::getVar( 'cid', array(0), '', 'array' );
$option = JRequest::getCmd( 'option');
$uid = (int) @$cid[0];
$edit = JRequest::getVar( 'edit', true );
$apoll =& JTable::getInstance('apoll', 'Table');
// load the row from the db table
if($edit)
$apoll->load( $uid );
// fail if checked out not by 'me'
if ($apoll->isCheckedOut( $user->get('id') )) {
$msg = JText::sprintf( 'DESCBEINGEDITTED', JText::_( 'The poll' ), $apoll->title );
$this->setRedirect( 'index.php?option='. $option, $msg );
}
if ($apoll->id == 0)
{
// defaults
$row->published = 1;
}
$options = array();
$ordering = array();
if ($edit)
{
$options = $apoll->getOptions($apoll->id);
}
else
{
$apoll->lag = 24*60;
}
//default colors for slices
$colors = array("ff0000","ffff99","00ccff","66ff99","ffcc00","d7ebff","ccffcc", "cccccc", "ffff00", "006699", "660000", "ffddee");
$file = JPATH_COMPONENT.DS.'models'.DS.'apoll.xml';
$params = new JParameter( $apoll->params, $file );
$this->assignRef('apoll', $apoll);
$this->assignRef('options', $options);
$this->assignRef('showpie', $showpie);
$this->assignRef('params', $params);
$this->assignRef('color', $colors);
$this->assignRef('edit', $edit);
parent::display($tpl);
}
}
@@ -0,0 +1 @@
<html><body bgcolor="#FFFFFF"></body></html>
@@ -0,0 +1,156 @@
<?php
# @version $Id: administator/components/com_apoll/views/apolls/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'); ?>
<?php JHTML::_('behavior.tooltip'); ?>
<?php
JToolBarHelper::title( JText::_( 'Polls Manager' ) );
JToolBarHelper::publishList();
JToolBarHelper::unpublishList();
JToolBarHelper::deleteList();
JToolBarHelper::custom( 'resetVotes', 'help.png', 'save.png', 'Reset votes', true, false );
JToolBarHelper::editListX();
JToolBarHelper::addNewX();
JToolBarHelper::preferences( 'com_apoll', '500' );
?>
<form action="index.php?option=com_apoll" method="post" name="adminForm">
<table>
<tr>
<td align="left" width="100%">
<?php 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>
</td>
<td nowrap="nowrap">
<?php echo $this->lists['state']; ?>
</td>
</tr>
</table>
<div id="tablecell">
<table class="adminlist">
<thead>
<tr>
<th width="5">
<?php echo JText::_( 'NUM' ); ?>
</th>
<th width="20">
<input type="checkbox" name="toggle" value="" onclick="checkAll(<?php echo count( $this->items ); ?>);" />
</th>
<th class="title">
<?php echo JHTML::_('grid.sort', 'Poll Title', 'm.title', @$this->lists['order_Dir'], @$this->lists['order'] ); ?>
</th>
<th width="5%" align="center">
<?php echo JHTML::_('grid.sort', 'Published', 'm.published', @$this->lists['order_Dir'], @$this->lists['order'] ); ?>
</th>
<th width="5%" align="center">
<?php echo JHTML::_('grid.sort', 'Start', 'm.publish_up', @$this->lists['order_Dir'], @$this->lists['order'] ); ?>
</th>
<th width="5%" align="center">
<?php echo JHTML::_('grid.sort', 'End', 'publish_down', @$this->lists['order_Dir'], @$this->lists['order'] ); ?>
</th>
<th width="5%" align="center">
<?php echo JHTML::_('grid.sort', 'Votes', 'votes', @$this->lists['order_Dir'], @$this->lists['order'] ); ?>
</th>
<th width="5%" align="center">
<?php echo JHTML::_('grid.sort', 'Options', 'numoptions', @$this->lists['order_Dir'], @$this->lists['order'] ); ?>
</th>
<th width="5%" align="center">
<?php echo JHTML::_('grid.sort', 'Lag', 'm.lag', @$this->lists['order_Dir'], @$this->lists['order'] ); ?>
</th>
<th width="1%" nowrap="nowrap">
<?php echo JHTML::_('grid.sort', 'ID', 'm.id', @$this->lists['order_Dir'], @$this->lists['order'] ); ?>
</th>
</tr>
</thead>
<tfoot>
<tr>
<td colspan="10">
<?php echo $this->pagination->getListFooter(); ?>
</td>
</tr>
</tfoot>
<tbody>
<?php
$k = 0;
for ($i=0, $n=count( $this->items ); $i < $n; $i++)
{
$row = &$this->items[$i];
$link = JRoute::_( 'index.php?option=com_apoll&view=apoll&task=edit&cid[]='. $row->id );
$checked = JHTML::_('grid.checkedout', $row, $i );
$published = JHTML::_('grid.published', $row, $i );
?>
<tr class="<?php echo "row$k"; ?>">
<td>
<?php echo $this->pagination->getRowOffset( $i ); ?>
</td>
<td>
<?php echo $checked; ?>
</td>
<td>
<?php if ( JTable::isCheckedOut($this->user->get ('id'), $row->checked_out ) ) {
echo $row->title;
} else {
?>
<span class="editlinktip hasTip" title="<?php echo JText::_( 'Edit Poll' );?>::<?php echo $row->title; ?>">
<a href="<?php echo $link ?>">
<?php echo $row->title; ?></a></span>
<?php
}
?>
</td>
<td align="center">
<?php echo $published;?>
</td>
<td align="center">
<?php echo $row->publish_up;?>
</td>
<td align="center">
<?php echo $row->publish_down;?>
</td>
<td align="center">
<a href="index.php?option=com_apoll&task=view&view=votes&total=<?php echo $row->votes; ?>&id=<?php echo $row->id; ?>"><?php echo $row->votes; ?></a>
</td>
<td align="center">
<?php echo $row->options; ?>
</td>
<td align="center">
<?php echo $row->lag/60; ?>
</td>
<td align="center">
<?php echo $row->id; ?>
</td>
</tr>
<?php
$k = 1 - $k;
}
?>
</tbody>
</table>
</div>
<input type="hidden" name="option" value="com_apoll" />
<input type="hidden" name="task" value="" />
<input type="hidden" name="boxchecked" value="0" />
<input type="hidden" name="filter_order" value="<?php echo $this->lists['order']; ?>" />
<input type="hidden" name="filter_order_Dir" value="<?php echo $this->lists['order_Dir']; ?>" />
<?php echo JHTML::_( 'form.token' ); ?>
</form>
@@ -0,0 +1 @@
<html><body bgcolor="#FFFFFF"></body></html>
@@ -0,0 +1,56 @@
<?php
# @version $Id: administator/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');
class ApollsViewApolls extends JView
{
function display( $tpl = null )
{
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' );
$filter_state = $mainframe->getUserStateFromRequest( "$option.filter_state.apolls", 'filter_state', '', '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' );
// state filter
$lists['state'] = JHTML::_('grid.state', $filter_state );
// table ordering
$lists['order_Dir'] = $filter_order_Dir;
$lists['order'] = $filter_order;
// search filter
$lists['search']= $search;
$this->assignRef('user', JFactory::getUser());
$this->assignRef('lists', $lists);
$this->assignRef('items', $items);
$this->assignRef('pagination', $pagination);
parent::display($tpl);
}
}
@@ -0,0 +1 @@
<html><body bgcolor="#FFFFFF"></body></html>

Some files were not shown because too many files have changed in this diff Show More